==operation is special: it is translated to a complex expression that screens for
null == nullis always true, and
x == nullfor a non-null
xis always false and won’t invoke
This seems wrong with kotlin 1.3 because when x is not null, I can see ‘x == null’ invokes x.equals(null) when I tested it - I used IntelliJ Community Edition with kotlin language version and API version of 1.3.
And the explanation on the kotlinlang website seems like different from that on github page.
(I’m not sure which version on github to attach as a link, but I think they’re mostly same.)
==operation is special in two ways:
- It is translated to a complex expression that screens for
null == nullis
- It looks up a function with a specific signature , not just a specific name . The function must be declared as
fun equals(other: Any?): Boolean