開発環境
- macOS Mojave - Apple (OS)
- Windows 10 Pro (OS)
- IntelliJ IDEA CE(Community Edition) (IDE(統合開発環境))
- Kotlin (プログラミング言語)
Head First Kotlin: A Brain-Friendly Guide (Dawn Griffiths(著)、David Griffiths(著)、O'Reilly Media)のChapter 7(data classes - Dealing with Data)、Mixed Massages(203)の解答を求めてみる。
コード
data class Movie(val title: String, val year: String) class Song(val title: String, val artist: String) fun main() { var m1 = Movie("Black Panther", "2018") var m2 = Movie("Jurassic World", "2015") var m3 = Movie("Jurassic World", "2015") var s1 = Song("Love Cats", "The Cure") var s3 = Song("Love Cats", "The Cure") println((m2 == m3) == true) println((s1 == s3) == false) var m4 = m1.copy() println((m1 == m4) == true) var m5 = m1.copy() println((m1 === m5) == false) var m6 = m2 m2 = m3 println((m3 == m6) == true) }
入出力結果
true true true true true Process finished with exit code 0
0 コメント:
コメントを投稿