如何从内部类中的方法获取父对象?嵌套类的对象如何访问它们嵌套的对象?
class OuterClass {
public outerMethod() {
// this refers to the object in the outer class
}
class InnerClass {
public innerMethod() {
// this refers to the object in the inner class
// How do I get my current parent object
}
}
}
一种方法是添加像
public OuterClass getthis() {
return this;
}
任何其他建议的方法?有没有从java本身的方式?
更新了类名。对困惑感到抱歉。 – EFreak 2011-02-15 10:28:15