我需要使用內部類中外部類的指針this
。是否可以從嵌套類引用outter類指針?
我不知道如何去做,而不保存this
指針。有其他選擇嗎?
class outerclass {
outerClass thisPointer;
outerclass() {
//
// NOTE: I am saving this pointer here to reference
// by the inner class later. I am trying to find
// a different alternative instead of saving this pointer.
//
thisPointer = this;
}
class innerClass {
void doSomething() {
//
// is there a way to reference the outter class
// without having to save the thisPointer from
// the outter class.
// NOTE someObject is a class outside of the
// outterclass control.
//
someObject.someMethod (thisPointer);
}
}
}
Java的引用不是指針。 ;) –