It is often claimed that the implementation of Object.hashCode()
(the default implementation for all objects) gives the memory address of the object. That claim is often attached to an explanation of the peculiar output produced by Object.to String().
See here for an example.
This is certainly not the case for any JVMs/JREs I am aware of. Not least because addresses are usually 64 bits long now. But also, garbage collectors relocate objects, so the address changes. I've seen claims it can be the initial memory address of the object. But as many objects would then have similar addresses, that would be a poor choice for a hash code.
Are there, or have there ever been, any widely used JVMs/JREs for which it was the (initial) memory address of the object.
I am aware that the JavaDoc for the Object
class suggests that the hashCode
for an implementation might be the memory address. But I suspect that is a grossly out of date statement that has never been updated.
Indeed, the current Oracle JVM does not use the memory address (but can be configured to do so):
https://stackoverflow.com/a/16105878/545127
The idea that the hashCode is a memory address is a historical artefact:
https://stackoverflow.com/a/13860488/545127
My question is whether (and which) any widely used JVM used the memory address as its (default) implementation.