Listener owner class call

Having the following class -

public class GUIclass1 extends org.eclipse.swt.widgets.Composite {
    private void initGUI() {

        {
            // The setting of the open file button.
            openButton = new Button(this, SWT.PUSH | SWT.CENTER);
            openButton.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent evt) {
                    foo() ; 
                }
            });
        }
    }

    public void foo() {
        // implementation ..
    }
}

As you can see in addSelectionListener, there is a method call foo().

My question is: which link should I write as a prefix for foo(), to find out which class it foo()belongs to.

I tried super().foo()without success.

+5
source share
2 answers

Would you call him GUIclass1.this.foo()

+8
source

Try it,

As you know an inner class has an implicit access to the members of the outer class, therefore this.foo() Will NOT work, But

GUIclass1.this.foo() Will WORK.

0
source

All Articles