前回 Kotlin の案件に参加しこの言語を体系的に扱った。それを自分視点で改めてまとめる。
↓ このサンプルがベーシックで一番分かりやすい。
https://github.com/Kotlin/kotlin-by-example/tree/master/examples
先ずは Data classes のところ
data class User(val name: String, val id: Int) {
override fun equals(other: Any?) = // 1
other is User && other.id == this.id // 2
}
→ ディフォルトメソッドをオーバーライドする。全メンバーが等しくてオブジェクトが等しい、とするディフォルトをここでは id が等しければ、インスタンスが等しいとする、とするという物。
//1 → other: Any? nullありの全ての型のother,
//2 → other が User のインスタンスの場合( Javaの instanceOf 相当 )、かつ other の id と自分の id が等しければ true