October 22, 2024
Chicago 12, Melborne City, USA
java

How to access the top level/enclosing class instance having the instance of the inner class


NOTE: I’m not talking about the way of accessing the enclosing class FROM the inner class, that is not the problem at all. What I’m talking about is the following:

class TopLevel {

    class InnerClass {
    }
}


// in some other class A.java
public void execute(InnerClass ic) {

}

Here, in the execute() method, we have the instance of the InnerClass passed as an argument. So what I actually want is to access the instance of Enclosing class, inside which the InnerClass instances that was passed to execute() was created.

How can this be achieved?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video