5
Tôi không biết tại sao đoạn code scala sau đây không thể được biên dịch:lỗi biên dịch scala: loại không phù hợp; tìm thấy: IndexedSeq [Int] yêu cầu: 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)
^
Trong thư viện scala, IndexedSeq được khai báo:
trait IndexedSeq[+A] extends Seq[A]...
Oh. Bởi vì có một số đặc điểm IndexedSeq. Mặc định là scala.collection.IndexedSeq. nếu tôi nhập collection.immutable.IndexedSeq thì scala sẽ biên dịch thành công –
Đăng câu trả lời vì lợi ích của người dùng khác :) – theon