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

  • Mr_BrettHooge

    Mr_BrettHoog

    3 Ocak 2011
  • RiverCityGraphix

    RiverCityGra

    6 Ocak 2012
  • TomKNJ

    TomKNJ

    26 ŞUBAT 2007