I am trying to refer to the class a nested class is 'in'... The 'this' keyword refers to the nested class, so I need something like super.this (except not at all like that) :/

I think the code below describes what I am trying to do:

public class Nest {
   
    private String var = "foo";
    private MyOtherClass myOtherClass;

    private class Nested {
        public doSomething() {
            //Here I want to access the class this is nested in,
            //now this should be really easy (i can access the
            //variable foo) but 'this' is for the Nested instance
            myOtherClass = new MyOtherClass(######);
            //what do I need to put here: ###### to refer to the Nest?
        }
    }  
}

public class MyOtherClass{
   
    private Nest parentNest;

    public MyOtherClass(Nest nest){
        parentNest = nest;
    }  
}

Can anybody help? ^_^

Edited 5 Years Ago by hanvyj: n/a

you should put Nest.this like below

myOtherClass = new MyOtherClass(Nest.this);

Comments
answerd it in two lines!
Nest nest = new Nest();
myOtherClass = new MyOtherClass(nest);

This creates an instance(object) of your Nest class.

you should put Nest.this like below

myOtherClass = new MyOtherClass(Nest.this);

Well, it was as simple as I thought it should be! Its a real pain when you know exactly what you want to do but are unsure of how to search for the answer.

Thanks!

This question has already been answered. Start a new discussion instead.