I was learning about the Singleton design pattern through a tutorial. Basically from what I understand it ensures that only one instance of a class is ever created, and any interaction with that class is done through that one instance in the heap. with that said, in the SingletonPatternDemo.java I wrote:
SingleObject object1 = SingleObject.getInstance();
SingleObject object2 = SingleObject.getInstance();
from my understanding, both object1 and object2 reference the same object, thus they should point to the same location in memory.
However when I write:
System.out.println("object1 HashCode: " + System.identityHashCode(System.identityHashCode(object1)));
System.out.println("object2 HashCode: " + System.identityHashCode(System.identityHashCode(object2)));
after I run it I get:
object1 HashCode: 865113938
object2 HashCode: 1442407170
since these two objects reference the same instance shouldn't they return the same hashcode? or am I missing something?