如何从内部类中的方法获取父对象?
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
一种方法是添加一个类似的方法
public OuterClass getthis() {
return this;
}
Run Code Online (Sandbox Code Playgroud)
还有其他建议吗?有没有办法从java本身?
| 归档时间: |
|
| 查看次数: |
1203 次 |
| 最近记录: |