Taken from here
The contract between equals() and hashCode() is:
1) If two objects are equal, then they must have the same hash code.
2) If two objects have the same hash code, they may or may not be equal.
Therefore: any class that defines equals()
differently than this == other
must have its own implementation of hashCode()
solved What classes in java are overriding equals() and hashCode() methods? [closed]