I know i can get the instance of the enclosing class using:
OuterClass.this
But i can do it only within the inner class code itself. only I have is reference of the Inner class instance withing another class code. How can i get the OuterClass instance through the inner class instance?
You can define a getter that returns OuterClass to callers from the outside:
public class InnerClass {
...
public OuterClass getOuterInstance() {
return OuterClass.this;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With