Scala - 匿名类没有得到调用者类的变量

时间:2017-03-10 22:41:52

标签: scala class anonymous

我正在创建一个扩展CollaborativeFilterModel的匿名类。我想在train方法中返回matrixFactorizationModelMock,但无法解析。请注意,matrixFactorizationModelMock是在匿名类之外定义的。

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

      }

有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:1)

嗯,你应该返回matrixFactorizationModelMock而不是matrixFactorizationModel ...