elect
05/24/2019, 11:04 AMoverride fun equals(other: Any?): Boolean = when(other) {
this -> true
will other
checked using == or === ?Marko Mitic
05/24/2019, 11:09 AMJonathan Mew
05/24/2019, 11:09 AM@Test
fun testOther() {
class Test {
override fun equals(other: Any?): Boolean {
return true
}
}
val t1 = Test()
val t2 = Test()
Test().equals(Test()) shouldBe true
(Test() === Test()) shouldBe false
val maybe = when (t1) {
t2 -> "yes"
else -> "no"
}
println(maybe)
}
yes
elect
05/24/2019, 11:10 AMelect
05/24/2019, 11:13 AMother === this
Marko Mitic
05/24/2019, 11:13 AMStackOverflowError
Marko Mitic
05/24/2019, 11:14 AM==
tseisel
05/24/2019, 12:18 PMoverride fun equals(other: Any?): Boolean = when {
other === this -> true
// Check the type, then the equality of each properties
}
Also, why not using a data class
? equals
and hashcode
are implemented automatically by the compiler.elect
05/24/2019, 12:19 PMdata class
is out because of thiselect
05/24/2019, 12:19 PMequals
is actually more complex than what I shown)karelpeeters
05/24/2019, 1:53 PMto be the same as
===`?elect
05/24/2019, 5:33 PMwhen(value)
karelpeeters
05/24/2019, 6:06 PM