0

Where will Anonymous objects are stored in JVM memory. How to get hashcode of the Object?

public class Outer {
    
    public class Inner {
        
        public void display() {
            System.out.println("Inner class method");
        }
    }
    
    public static void main(String[] args) {
            
        new Outer().new Inner().display();
    }
}
``
Holger
  • 285,553
  • 42
  • 434
  • 765
  • 1
    Would it make sense to add `java` and/or `jvm` Tags in order to address the desired audience? – Stefan Wuebbe Nov 02 '22 at 15:56
  • 2
    All objects are stored in the heap memory. The fact that you don’t store a reference to the object doesn’t change the nature or storage type of the object. Of course, if you don’t store a reference to the object, it may get garbage collected at any point. There is no reason to assume that you can get the hash code of an unreachable object. By the way, your inner class is not anonymous, as it has the name `Inner`. – Holger Mar 02 '23 at 12:53

0 Answers0