You could just simplify this all to `it == obj` - ...
# announcements
s
You could just simplify this all to
it == obj
- the only caveat is that if
it
and
obj
are both
null
- you'll get
true
. If that's not desired, then this would yield the same result as the original code
it != null && it == obj
s
This assumes that
it
and
obj
are of the same type. Using equals allows for a custom comparison function. In this case I have a custom data class which I want to support a comparison to an ID of type Long.
s
sure, but doesn’t
==
translate to a
.equals()
call in Kotlin?
or am I missing an edge case or something else unintuitive?
s
Yes @Shawn you are correct, in kotlin
a == b
and
a.equals(b)
are identical. @spragg if you want the java "==" you'll have to use === in kotlin.
s
Nice, yeah it does. @StavFX I only had that second part in to support matching a
null
, and since that is taken care of by what == is translated to. I can do what I need by just having
a == b
👍 1