SORU
3 NİSAN 2011, Pazar


Java: Sınıf.bu

Böyle bir Java programı var.

public class LocalScreen extends Something {
   .....
   public void onMake () {
      ...
      aFuncCall (LocalScreen.this, oneString, twoString);
      ...
   }
}

"LocalScreen.ne demek bu aFuncCall?" anlamına gelir

CEVAP
3 NİSAN 2011, Pazar


LocalScreen.this çevreleyen sınıf this anlamına gelir.

Bu örneği açıklamak gerekir:

public class LocalScreen {

    public void method() {

        new Runnable() {
            public void run() {
                // Prints "An anonymous Runnable"
                System.out.println(this.toString());

                // Prints "A LocalScreen object"
                System.out.println(LocalScreen.this.toString());

                // Won't compile! 'this' is a Runnable!
                //onMake(this);

                // Compiles! Refers to enclosing object
                onMake(LocalScreen.this);
            }

            public String toString() {
                return "An anonymous Runnable!";
            }
        }.run();
    }

    public String toString() { return "A LocalScreen object";  }

    public void onMake(LocalScreen ls) { /* ... */ }

    public static void main(String[] args) {
        new LocalScreen().method();
    }
}

Çıkış:

An anonymous Runnable!
A LocalScreen object

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Blue Lightning TV

    Blue Lightni

    9 EKİM 2011
  • Ciaran Blumenfeld

    Ciaran Blume

    20 NİSAN 2009
  • RiceBunny

    RiceBunny

    16 ŞUBAT 2006