如何訪問與內部類的內部類成員實例或方法局部變量具有相同名稱的方法變量?方法本地內部類成員範圍訪問
class A{
int a = 10; //1
public void someMethodA(){
final int a = 20; //2
class B{
int a = 30; //3
public void someMethodB(){
int a = 40; //4
System.out.println("a = "+a); //access 4
System.out.println("a = "+this.a); //access 3
System.out.println("a = "+A.this.a); //access 1
System.out.println(?????); //how do I access value of a i.e 2
}
}
}
}
該代碼將永遠不會輸出這些語句,但它確實編譯 – NimChimpsky