5

有以下课程 -

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 ..
    }
}

正如您在其中看到的,addSelectionListener有一个对方法的调用foo()

我的问题是 -foo()为了知道哪个类foo()与 .

我试过super().foo()没有成功。

4

2 回答 2

8

你会称它为GUIclass1.this.foo()

于 2012-06-10T14:49:12.050 回答
0

试试这个,

我们知道an inner class has an implicit access to the members of the outer class,所以this.foo() Will NOT work,但是

GUIclass1.this.foo() Will WORK.

于 2012-06-10T14:55:43.203 回答