Victor Molina
Victor Molina

Reputation: 2641

Get the outer class reference in a nested class

I am trying to get an outer class reference in a nested class. Basically, I have a class inside another, so when I try to use the keyword "this" it doesn't reference the parent.

public class A extends JPanel {
  public A() {
     ...
     options.add(new JMenuItem(new AbstractAction("item") {
            public void actionPerformed(ActionEvent e) {
                window.setOldPanel(this); // this is the ActionEvent, not what I want (the outer class reference)
            }
        }
     )))
  }
}

Is there any way to do this without creating an instance of the parent in the nested?

Thanks.

Upvotes: 0

Views: 37

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198033

You're looking for A.this, which properly refers to the A this.

Upvotes: 2

Related Questions