Introduction to JVM Languages
上QQ阅读APP看书,第一时间看更新

About hashCode()

As the name suggests, this method is called when a hash of the object in question is needed.

The hashCode() method is supposed to return an integer value that changes when the content of the object changes. Also, if possible, it should return a value that, ideally, is distinct from other similar objects.

It's not an error to return a value that does not identify the object, but this will negatively impact the performance of most Collection classes. This is explained in more detail below.