SORU
5 Temmuz 2009, Pazar


Erişim "bu" Java anonim sınıf

Verilen takip kodu:

public interface Selectable {
  public void select();
}

public class Container implements Selectable {
  public void select() {
  ...
  }
  public void createAnonymousClass() {
    Selectable s = new Selectable() {
      public void select() {
        //see comment below.
      }
    };
  }
}

Anonim benim sınıf içinde Container.select() giriş select() yöntem istiyorum. Ancak, this.select() yine anonim sınıfı' select() yöntem değil.

Benim önerim şöyle olacaktır:

Kabın içine alan, örneğin tanıtmak

private Container self = this;

Şimdi anonim bir sınıf içinde self.select() çağırarak Container.select() giriş yapabiliriz.

Bu makul bir yolu var mı? Ya da daha iyi bir yolu var mı?

CEVAP
5 Temmuz 2009, Pazar


Container.this.select();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • midomansour

    midomansour

    19 EYLÜL 2009
  • Pepsi

    Pepsi

    1 Kasım 2005
  • The Bad Tutorials

    The Bad Tuto

    6 EKİM 2009