Scala - 匿名 class 没有获取调用者的变量 class

Scala - Anonymous class not getting variable of caller class

我正在创建一个匿名 class 扩展 CollaborativeFilterModel。我想在train方法中returnmatrixFactorizationModelMock,但是无法解析。请注意,matrixFactorizationModelMock 是在匿名 class.

之外定义的
class CollaborativeFilterTest extends FunSuite with EasyMockSugar {

  test("Index mapping"){

    val matrixFactorizationModelMock = mock[MatrixFactorizationModel]

    //Start of anonymous class definition:

    val model = new CollaborativeFilterModel(){

      override def train(ratings: Dataset[Rating]): MatrixFactorizationModel = {

        matrixFactorizationModelMock //Cannot resolve symbol matrixFactorizationModelMock

      }

有什么建议吗?谢谢!

嗯,你应该 return matrixFactorizationModelMock 而不是 matrixFactorizationModel...