According to this post:
http://coding-geek.com/how-does-a-hashmap-work-in-java/
java 8 hashmaps use a treenode instead of a linkedlist (as in java 7) as elements of the array.
TreeNodes have the special property of acting as a linkedlist if the number of elements are small, and acting as a red black tree if there is a large number of elements. (Since operations involving a red black tree are log(n)).
However, doesn't this require the key to be Comparable or some ordering of the keys to exist?
Is this enforced in the java 8 hashmap? Will it only use red black trees if the keys are Comparable (ordering of keys exist)?
System.identityHashCodeto order the tree nodes. This is the hash code that's used by default if you don't supply your ownhashCode(), and it's based on the reference (sort of like the "address"). All that matters is that some consistent value be used, andidentityHashCodeis good enough.hashCode() % bucketCount. If two objects are going into the same bucket, that means thathashCode() % bucketCountwill be the same--but it does not mean that thehashCode()is the same. Therefore thehashCode()can still be used for comparison. And even if thehashCode()is the same, theSystem.identityHashCodewill still most likely be different.