Typically the default implementation of Object.hashCode()
is some function of the allocated address of the object in memory (though this is not mandated by the JLS). Given that the VM shunts objects about in memory, why does the value returned by System.identityHashCode()
never change during the object's lifetime?
If it is a "one-shot" calculation (the object's hashCode
is calculated once and stashed in the object header or something), then does that mean it is possible for two objects to have the same identityHashCode
(if they happen to be first allocated at the same address in memory)?