When I input Seq(1,2,3)
in REPL, it returns me List(1,2,3)
scala> Seq(1,2,3)
res8: Seq[Int] = List(1, 2, 3)
Therefore, I thought the List(1,2,3)
may be of type List[Int]
. And I tried to specify the type for the variable who are assigned to Seq(1,2,3)
, but unexpectedly, the REPL complains like this:
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)
Does anyone have ideas about what Seq[Int] = List(1, 2, 3)
mean? Shouldn't it mean Seq(1,2,3)
returns a list? What is the difference between Seq[Int]
and List[Int]
?
And how to convert between Seq
and List
?