zoukankan      html  css  js  c++  java
  • java中this$0 this$1 this$2

    import java.lang.reflect.Field;

    public class Outer {//this$0

    public class FirstInner {//this$1

    public class SecondInner {//this$2

    public class ThirdInner {
    }
    }
    }

    public static void main(String[] args) throws Exception {

    //初始化各内外实例
    Outer test = new Outer();
    FirstInner first = test.new FirstInner();
    FirstInner.SecondInner second = first.new SecondInner();
    FirstInner.SecondInner.ThirdInner third = second.new ThirdInner();

    System.out.println(test.hashCode());
    System.out.println(first.hashCode());
    System.out.println(second.hashCode());

    //Outer,this$0
    Field outerfield = first.getClass().getDeclaredField("this$0");
    outerfield.setAccessible(true);
    Object object = outerfield.get(first);
    System.out.println(object.getClass()+","+object.hashCode());

    //FirstInner,this$1
    Field firstInnerfied = second.getClass().getDeclaredField("this$1");
    firstInnerfied.setAccessible(true);
    object = firstInnerfied.get(second);
    System.out.println(object.getClass()+","+object.hashCode());

    //SecondInner,this$2
    Field secondInnerfield = third.getClass().getDeclaredField("this$2");
    secondInnerfield.setAccessible(true);
    object = secondInnerfield.get(third);
    System.out.println(object.getClass()+","+object.hashCode());

    }
    }

    运行结果:

    1163157884
    1956725890
    356573597
    class my.test.Outer,1163157884
    class my.test.Outer$FirstInner,1956725890
    class my.test.Outer$FirstInner$SecondInner,356573597



  • 相关阅读:
    [zz]利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
    [zz]va_start() 和 va_end()函数应用
    [zz]shmdt与shmctl的区别
    [zz]GNU C 扩展之__attribute__ 机制简介 [2]
    Linux errno 错误含义速查
    过滤器的简介
    MyBatis中的原理
    文件上传
    mybatis实体为什么要提供一个无参的构造函数
    为什么要有无参构造方法
  • 原文地址:https://www.cnblogs.com/qiumingcheng/p/9667426.html
Copyright © 2011-2022 走看看