Effective Java! Obey the `hashCode` contract
Today’s topic goes right in line with last week’s. This week we are talking about the
hashCode function. Just like the
equals function we talked about last week this method also has a contract that should be followed albeit a simpler one. As is the signature, taking no parameters and return an integer. So lets get to the contract:
- Given no changes to an object the value returned from the function should remain the same.
- If two objects are effectively equals their hashcodes must be the same.