The implementation of equals()
and hashCode()
should follow these rules.
- If
o1.equals(o2)
, theno1.hashCode() == o2.hashCode()
should always be true. - If
o1.hashCode() == o2.hashCode()
is true, it doesn’t mean thato1.equals(o2)
will be true.
If o1.hashCode() == o2.hashCode()
is true . i know, that If two objects are equals then these two objects should return same hash code. if two objects hash code is a same, why does it not mean that o1.equals(o2)
?