来自匿名内部类的外部类的关键字 [英] Keyword for the outer class from an anonymous inner class

查看:102
本文介绍了来自匿名内部类的外部类的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码段中:

public class a {
    public void otherMethod(){}
    public void doStuff(String str, InnerClass b){}
    public void method(a){
        doStuff("asd",
            new InnerClass(){
                public void innerMethod(){
                    otherMethod();
                }
            }
        );
    }
}

是否有关键字来引用外部类内心阶级?基本上我想做的是 outer.otherMethod(),或类似的东西,但似乎找不到任何东西。

Is there a keyword to refer to the outer class from the inner class? Basically what I want to do is outer.otherMethod(), or something of the like, but can't seem to find anything.

推荐答案

通常你使用 OuterClassName.this 来引用外部类的封闭实例。

In general you use OuterClassName.this to refer to the enclosing instance of the outer class.

在您的示例中, a.this.otherMethod()

这篇关于来自匿名内部类的外部类的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆