简体   繁体   English

另一个内部类的内部子类-根类有多少个引用?

[英]Inner subclass of another inner class - how many refs to the root class?

Suppose I have the structure 假设我有结构

class A {
    class B {}
    class C extends B {}
}

It seems that instances of C should have 2 references to the root class A : the first is inherited from B superclass, the second is own implicit inner class reference. 似乎C实例应该有2个对根类A引用:第一个是从B超类继承的,第二个是自己的隐式内部类引用。 My question: does JVM (HotSpot) optimize this case and keep only one reference to the root class? 我的问题:JVM(HotSpot)是否优化了这种情况并仅保留对根类的一个引用?

I decompiled A.class and got this result which shows two references to A, one from B and one from C. But this actually means that C actually has two references - one is its own and the other is inherited from B. 我对A.class进行了反编译,得到的结果显示了对A的两个引用,一个是B的引用,另一个是C的引用。但这实际上意味着C实际上有两个引用-一个是它自己的引用,另一个是从B继承的。

class A {

    class B {
        final A this$0;
        B() {
            this$0 = A.this;
        }
    }

    class C extends B {
        final A this$0;
        C() {
            this$0 = A.this;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM