2012-11-24 64 views
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]... 
+0

哦。因爲有幾個IndexedSeq特徵。默認是scala.collection.IndexedSeq。如果我導入collection.immutable.IndexedSeq然後scala將編譯成功 –

+0

作爲回答其他用戶的利益:) – theon

回答

3

有幾個IndexedSeq特徵。默認爲scala.collection.IndexedSeq。如果你import collection.immutable.IndexedSeq那麼scala會成功編譯。 (從OP複製)

相關問題