1

是否可以从 Java 中的封闭类访问封闭类的阴影字段?

public class Inherit {    

    public int a = 3;
    private int b = 5;
    public class Inheriting {
        public int a = 23;
        private int d = 8;
        public void f() {
            System.out.println("Here I want to get a = 3");
            ...
        }
    }
}
4

2 回答 2

2
public void f() {
    System.out.println("Here I want to get a = 3" + Inherit.this.a); 
}
于 2010-03-23T13:50:15.137 回答
1

是的,

Inherit.this.a;

但是您最好选择更具描述性的名称,以免它们发生冲突。

于 2010-03-23T13:47:30.540 回答