Java Interfaces and Memory Allocation

interface, java, memory-management, object-reference

Solution

Every object reference takes up the same amount of memory, no matter how you declare it.

So `x` and `obj` are two distict references, which just happen to point at the same thing.

Problem

Consider: ``` public SomeClass implements SomeInterface{...} SomeClass obj = new SomeClass(); SomeInterface x = obj; ``` I am trying to relate line 3 to my very basic understanding of memory management. I know the memory location represented by "obj" just contains a pointer to the memory location of SomeClass. Assuming I am using a 64bit JVM, then up to 64 bits are allocated for the "obj" pointer. What is created in memory when the JRE implements x? Is it just a 64bit pointer to SomeClass?

Original source