Han*_*Sun 5 containers functional-programming scala type-conversion
当我Seq(1,2,3)在REPL中输入时,它返回给我List(1,2,3)
scala> Seq(1,2,3)
res8: Seq[Int] = List(1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
因此,我认为List(1,2,3)可能是类型List[Int].我试图指定分配给变量的类型Seq(1,2,3),但出乎意料的是,REPL抱怨如下:
scala> val a:List[Int]=Seq(1,2,3)
<console>:20: error: type mismatch;
found : Seq[Int]
required: List[Int]
val a:List[Int]=Seq(1,2,3)
Run Code Online (Sandbox Code Playgroud)
有没有人有什么Seq[Int] = List(1, 2, 3)意思?它不应该意味着Seq(1,2,3)返回一个列表吗?Seq[Int]和之间有什么区别List[Int]?以及如何转换 Seq和List?