Possible Duplicate:
keyword for the outer class from an anonymous inner class?
我需要访问匿名内部类中外部类的实例并执行类似的操作。谁能澄清这是否正确?
public class ClassA{
ClassA refernceOfClassA = this;
public void m(){
//Do something
}
Runnable target = new Runnable(){
public void run(){
//Code goes here using the refernceOfClassA
refernceOfClassA.m();
}
};
}
最佳答案
您应该能够从内部类调用方法m()
。
public class ClassA{
public void m(){
//Do something
}
Runnable target = new Runnable(){
public void run(){
//Code goes here using the refernceOfClassA
m();
}
};
}
关于java - Java中匿名内部类内部访问外部类实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565000/