Getting all instances of an inner class from an instance of its outer class

85 views Asked by At

Let's say a Tree class has in inner Node class.

class Tree {
    ...
    class Node {
        ...
    }
}

I know that within the context of a Node instance, the outer instance, or the "owner" of the Node can be accessed using the qualified this:

Tree.this.someAction();

I'm looking for the exact opposite of this: a way to refer to and iterate over all Nodes owned by a given Tree object without keeping an explicit collection field in Tree.

Is this even possible without reflection?

0

There are 0 answers