Consider the following classes:
public class A {
public int a;
public class B {
public int b;
public void foo() {
System.out.println(A.this.a);
System.out.println(this.b);
}
}
}
In foo, I access the outer A instance from within B using the syntax A.this. This works well because I'm trying to access the outer instance of A from the "current object" in B. However, what do I do if I want to access the outer A object from a variable of type B?
public class A {
public int a;
public class B {
public int b;
public void foo(B other) {
System.out.println(other.A.this.a); // <-- This is (obviously) wrong. What SHOULD I do here?
System.out.println(other.b);
}
}
}
What's the correct syntax to access the "outer" instance from the "inner" instance other in foo?
I realize I can access the outer variable a using simply other.a. Please forgive the contrived example! I just couldn't think of a better way to ask how to reach other.A.this.