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