内部类语法糖之添加获取方法

 

 

class X{
    private int a = 1;
    private int b = 2;
    class Y{      
        public void t2() {
        	int x = a;
        	int y = new X().b;
        }
    }
}

解语法糖后结果如下: 

class X$Y {
    /*synthetic*/ final X this$0;
    X$Y(/*synthetic*/ final X this$0) {
        this.this$0 = this$0;
        super();
    }
    public void t2() {
        int x = X.access$000(this$0);
        int y = X.access$100(new X());
    }
}

class X {
    /*synthetic*/ static int access$100(X x0) {
        return x0.b;
    }
    /*synthetic*/ static int access$000(X x0) {
        return x0.a;
    }
    private int a = 1;
    private int b = 2;
}

 

 

 

class Parent{
	int a = 1;
}
class Test extends Parent{
	public void md() {
		int b = Test.super.a +super.a;
	}
}

解语法糖后如下:  

class Test extends Parent {
    
    /*synthetic*/ static int access$001(Test x0) {
        return x0.a;
    }

    public void md() {
        int b = Test.access$001(this) + super.a;
    }
}

注意super.a没有变化,而Test.super.a发生了变化  

 

 

 

 

 

 

 

  

 

你可能感兴趣的:(内部类语法糖之添加获取方法)