我试图在一个较小的例子上复制我的问题。我在以下代码片段中显示的位置收到编译错误。
class Outer {
class Inner
}
object OuterUtil {
val obj = new Outer
object xyz extends obj.Inner
//do something with xyz
}
//-------------------
object OuterUtil2 {
var m_obj: Outer = null
def createOuter() = {
m_obj = new Outer
}
def anotherMethod() {
//Compilation error here: stable identifier required,
//but OuterUtil2.this.m_obj found.
object xyz extends m_obj.Inner
}
}
object Test {
OuterUtil2.createOuter
OuterUtil2.anotherMethod
}
OuterUtil
工作正常。在OuterUtil2
中,我将功能拆分为两个功能。我将Outer
实例存储m_obj
为成员var
。该方法创建实例createOuter
并将其存储在. 在,我收到编译错误。如何修复?Outer
m_obj
anotherMethod
OuterUtil2