<https://www.reddit.com/r/Kotlin/comments/uzsjcy/s...
# stdlib
r
hashCode doesn't necessarily identify a unique object.
It's perfectly valid for two different instances to have the same hashCode.
e
the rule is that if two instances equal each other (via
.equals()
, which is
==
in Kotlin (except for NaN which we'll ignore here)), then they must have the same
hashCode()
. this implies the contrapositive (if two instances have different
hashCode()
then they must not be
==
), but does not imply the converse: it is allowed for two instances to have the same
hashCode()
but be
!=
👏 1
😮 2
and of course, as Rob brings up, the same
hashCode()
can be returned by
!==
instances (I'm just clarifying that it must be, for
==
instances)