-
-
Save FredDeschenes/2ef35f259b0e2065255e6fd2df87cf88 to your computer and use it in GitHub Desktop.
Kotlin data class inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface AbstractDTO { | |
val id: Int | |
} | |
interface AbstractPayment : AbstractDTO { | |
val amount: Int | |
fun something(): Int { | |
return amount + id | |
} | |
} | |
data class InternaltionalPayment(override val id: Int, override val amount: Int) : AbstractPayment | |
fun main(args: Array<String>) { | |
val dto = InternaltionalPayment(1, 10) | |
val same = InternaltionalPayment(1, 10) | |
val other = InternaltionalPayment(2, 12) | |
println(dto.something()) | |
println(same.something()) | |
println(other.something()) | |
println("--------------") | |
println(dto.hashCode()) | |
println(same.hashCode()) | |
println(other.hashCode()) | |
println("--------------") | |
println(dto == same) | |
println(dto == other) | |
println(same == other) | |
//11 | |
//11 | |
//14 | |
//-------------- | |
//41 | |
//41 | |
//74 | |
//-------------- | |
//true | |
//false | |
//false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment