如何从内部类访问外部类的“ this”?

llm:

是否可以this从Java内部类中获取对它的引用

class Outer {

  void aMethod() {

    NewClass newClass = new NewClass() {
      void bMethod() {
        // How to I get access to "this" (pointing to outer) from here?
      }
    };
  }
}
纪尧姆:

您可以这样访问外部类的实例:

Outer.this

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章