是否可以从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");
...
}
}
}
答案 0 :(得分:2)
public void f() {
System.out.println("Here I want to get a = 3" + Inherit.this.a);
}
答案 1 :(得分:1)
是的,
Inherit.this.a;
但是你最好选择更具描述性的名字,这样它们就不会发生冲突。