在以下代码片段中:
In the following snippet:
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()
或类似的操作,但似乎找不到合适的方法。
a.otherMethod()
不能正常工作吗? - T.ToduaOuterClassName.otherMethod()
表示一个静态方法,因此您需要使用OuterClassName.this
来获取外部类的实例。 - Bill the Lizard