2

The super-class can be referred to by the keyword, super, and the current class can be referred to via, this, but is there a way to refer to the class that contains the nested class/anonymous class?

cesar
  • 8,944
  • 12
  • 46
  • 59
  • possible duplicate of [keyword for the outer class from an anonymous inner class?](http://stackoverflow.com/questions/56974/keyword-for-the-outer-class-from-an-anonymous-inner-class) – aioobe Oct 17 '11 at 17:21

2 Answers2

3

Yes. Like this:

public class OuterClass {
    class InnerClass {
        void method() {
            // Refer to outer class instance
            doSomething( OuterClass.this );
        }

        void doSomething(OuterClass outer) {
            // ...
        }
    }
}
Community
  • 1
  • 1
Nate W.
  • 9,141
  • 6
  • 43
  • 65
3

I think you're looking for this answer.

Basically, if your outer class is called Container you use this syntax:

Container.this.methodNameGoesHere();

That will ensure that you will be calling the outer class's methodNameGoesHere() method even if there is a duplicate method in your anonymous class.

Community
  • 1
  • 1
Bob Cross
  • 22,116
  • 12
  • 58
  • 95