What is the default implementation of `hashCode`?

John Threepwood picture John Threepwood · Feb 28, 2013 · Viewed 59.7k times · Source

If one does not override the hashCode method, what is the default implementation of hashCode ?

Answer

default locale picture default locale · Feb 28, 2013

Then this class inherits hashCode from one of its ancestors. If non of them overrides it, then Object.hashCode is used.

From the docs:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

So default implementation is JVM-specific