if I type ```override fun equals(other: Any?): Boo...
# announcements
e
if I type
Copy code
override fun equals(other: Any?): Boolean = when(other) {
        this -> true
will
other
checked using == or === ?
m
if it doesn't return, it's ==
j
Copy code
@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
e
I cant test it yet, I'm in the middle of a port
isnt there a way to force structural equality then unless typing explicitely
other === this
m
StackOverflowError
uses
==
t
How about :
Copy code
override 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.
e
it's a port from C#, I'd like to keep it as closest as possible,
data class
is out because of this
(the
equals
is actually more complex than what I shown)
k
Do you want `equals`/`==
to be the same as
===`?
e
no, I wanted to know if I could use somehow structural equality if I had
when(value)
k
Then you'll need to do what @tseisel says.