I'm familiar with the ClassName.this
syntax to access the outer class instance of the current instance in the lexical scope of a nested inner class. What is the syntax to access the outer class instance of another instance?
For example, consider the following types:
public class A {
public int fieldA;
private class B {
public int fieldB;
public void foo(A.B other) {
/* Hypothetical code goes here... */
}
}
}
Inside B#foo
, I know I can use the syntax A.this.fieldA
to access the current instance's outer instance's field fieldA
. How do I access the same information for other
(e.g., something like other.B.this.fieldA
)?
I know I can add an instance method (e.g., getOuterInstance
) to B
that simply returns A.this
, which would let me call other.getOuterInstance()
in the above example. However, I'm hoping there's some built-in syntax I'm just not aware of.