Specifically when they're used with a moving garbage collectors. The current memory location of the object can't be used because it can change at the next collection, so what is used as the objects hash?
Asked
Active
Viewed 372 times
5
-
2The question should be: *How do VMs implement `System.identityHashCode()`*, as this is what is used by the IdentityHashMap. – Paŭlo Ebermann Jun 27 '11 at 01:32
-
possible duplicate of [How does the JVM ensure that System.identityHashCode() will never change?](http://stackoverflow.com/questions/1063068/how-does-the-jvm-ensure-that-system-identityhashcode-will-never-change) – Paŭlo Ebermann Jun 29 '11 at 23:10
2 Answers
0
As Paulo pointed out in his comment, System.identityHashCode()
is used for this. And from the javadocs:
Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode(). The hash code for the null reference is zero.
So, really, the question boils down to "What is the default hashCode algorithm?

jpm
- 3,165
- 17
- 24