5
我不知道爲什麼下面的Scala代碼不能被編譯:scala編譯錯誤:類型不匹配;發現:IndexedSeq [INT]要求:scala.collection.immutable.Seq [INT]
import collection.immutable.Seq
def foo(nodes: Seq[Int]) = null
val nodes:IndexedSeq[Int] = null
foo(nodes)
=>
error: type mismatch;
found : IndexedSeq[Int]
required: scala.collection.immutable.Seq[Int]
foo(nodes)
^
在scala庫中,IndexedSeq被聲明爲:
trait IndexedSeq[+A] extends Seq[A]...
哦。因爲有幾個IndexedSeq特徵。默認是scala.collection.IndexedSeq。如果我導入collection.immutable.IndexedSeq然後scala將編譯成功 –
作爲回答其他用戶的利益:) – theon