简体   繁体   中英

scala compile error: type mismatch; found: IndexedSeq[Int] required: scala.collection.immutable.Seq[Int]

I don't know why the following scala code can not be compiled:

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)
                 ^

In scala-library, IndexedSeq is declared:

trait IndexedSeq[+A] extends Seq[A]...

There are several IndexedSeq traits. Default is scala.collection.IndexedSeq . if you import collection.immutable.IndexedSeq then scala will compile successfully. (Copied from OP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM