开发者

Access Outer Class this instance

开发者 https://www.devze.com 2022-12-11 09:38 出处:网络
how do we access outer class this instance: eg in Class A { Class B { this.helloB(); 开发者_C百科(A\'s this).hello()

how do we access outer class this instance: eg in

Class A {

   Class B {

      this.helloB();
开发者_C百科      (A's this).hello()
   }
}

how do we access A's this instance in Java


Just call

A.this.hello()


By prefixing this with the class: A.this.hello()

Similarly, when you want to create an instance of B outside of A, you can use a.new B() (where a instanceof A == true).

0

精彩评论

暂无评论...
验证码 换一张
取 消