Beginner: Scala type alias in Scala 2.10?

后端 未结 2 1047
-上瘾入骨i
-上瘾入骨i 2021-02-02 13:13

Why does this code fail to compile with the error: not found: value Matrix? From the documentation and some (possibly out of date) code examples this should work?



        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 13:31

    From this article you have.

    Note also that along with most of the type aliases in package scala comes a value alias of the same name. For instance, there's a type alias for the List class and a value alias for the List object.

    A solution to the problem translates to:

    object TestMatrix extends App{  
      type Row = List[Int]
      val Row = List
      type Matrix = List[Row]
      val Matrix = List
    
      val m = Matrix( Row(1,2,3),
                      Row(1,2,3),
                      Row(1,2,3))
    }
    

提交回复
热议问题