2012-06-10 16 views
5

den sahibi sınıfa çağrılması -takip sınıfını sahip bir dinleyici

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

Eğer yönteme foo() bir çağrı var addSelectionListener içinde görebileceğiniz gibi.

Soruma ilişkin soru - hangi referansı foo() ile ilgili olarak yazmalıyım, hangi sınıfın foo() ilgili olduğunu öğrenmek için.

super().foo()'u denemeden denedim.

cevap

8

Sen Bildiğimiz gibi, GUIclass1.this.foo()

0

bu deneyin olarak

çağırır an inner class has an implicit access to the members of the outer class, yüzden this.foo() Will NOT work, Ama

GUIclass1.this.foo() Will WORK söyledi.

İlgili konular