Skip to content

Instantly share code, notes, and snippets.

@FredDeschenes
Last active February 1, 2018 18:02
Show Gist options
  • Save FredDeschenes/2ef35f259b0e2065255e6fd2df87cf88 to your computer and use it in GitHub Desktop.
Save FredDeschenes/2ef35f259b0e2065255e6fd2df87cf88 to your computer and use it in GitHub Desktop.
Kotlin data class inheritance
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