Consider the following:Map<Class<?>, Object> myMap = new HashMap<Class<?>, Object>(); Foo fooObject = New Foo(); myMap.put(fooObject.getClass(), fooObject)
After reading the source code of JDK, I am still surprised that the strings "AaAa", "AaBB" and "BBBB" have the same hashcode.
I was looking at the implementation of HashMap in JDK8. In the get methods, I saw the below line which is used to find the Node that matches with the given key.
Below is the source code snippet of String.hashCode() method from Java 8 (1.8.0_131 to be precise) You can see that, the documentation says, that hashCode() is computed using below formula