Quando sono entrata in Seq(1,2,3)
REPL, mi restituisce List(1,2,3)
La differenza e la conversione tra Seq [Int] e List [Int] in scala?
scala> Seq(1,2,3)
res8: Seq[Int] = List(1, 2, 3)
Pertanto, ho pensato che il List(1,2,3)
può essere di tipo List[Int]
. E ho cercato di specificare il tipo per la variabile che sono assegnati a Seq(1,2,3)
, ma inaspettatamente, il REPL si lamenta così:
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)
Qualcuno ha idee su ciò che Seq[Int] = List(1, 2, 3)
dire? Non dovrebbe significare che Seq(1,2,3)
restituisce una lista? Qual è la differenza tra Seq[Int]
e List[Int]
? E come convertire tra Seq
e List
?
Possibile duplicato? http://stackoverflow.com/questions/10866639/scala-difference-between-a-seq-and-a-list – StuartLC
@StuartLC Sì, ma non ha menzionato come convertire da 'Seq' a' List' o 'Lista' a' Seq' .. –