Each inner class instance "lives" in an instance of its outer class. The question is - how to refer to the instance of the outer class given the instance of the inner class when the inner class has no member pointing to its outer-class instance?
Eg: In the following, the method check()
provides the desired reference to the Outer
class instance from within Inner
for the ultimate use.
public class Outer {
int cnt = 0;
class Inner {
boolean check() {
return cnt==10;
}
}
public static void stuff(Outer.Inner in) {
if (in.check())
// if (<cnt value of its enclosing Outer class instance is 10>)
// do sth here
;
}
}
However - assume the method check()
didn't exist.
public class Outer {
int cnt = 0;
class Inner {
}
public static void stuff(Outer.Inner in) {
if (<cnt value of its enclosing Outer class instance is 10>)
// do sth here
;
}
}
Then, what is the syntax to refer to the outer-class instance of Outer.Inner in
so that one can refer to cnt
member of that instance and go from there without changing the Inner
class code in any way?
Note: seen Reference outer class instance from inner class and How to refer to Enclosing class from Inner class? among some other discussions. I'm looking to reach the outer class instance NOT from within the inner class instance itself.
TIA.
//----------------
EDIT:
boldfaced one crucial part of the clue.