Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2168
  • Last Modified:

Get Reference to Parent Class

If you have a nested class inside a parent class, the 'this' keyword will of course refer to an instance of the nested class when used inside the nested class.  But is there any way to get a reference to an instance of the parent class, without passing one over to the constructor of the nested class?  
public class Parent
{
    class Nested
    {
        void doSomething()
        {
            Parent p = this; // <--- doesn't work because 'this' refers to an instance of Nested
        }
    }          
}

Open in new window

0
chsalvia
Asked:
chsalvia
1 Solution
 
objectsCommented:
           Parent p = Parent.this;

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now