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

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 –

+0

Đăng câu trả lời vì lợi ích của người dùng khác :) – theon

Trả lời

3

Có một số đặc điểm IndexedSeq. Mặc định là scala.collection.IndexedSeq. nếu bạn import collection.immutable.IndexedSeq thì scala sẽ biên dịch thành công. (Sao chép từ OP)

Các vấn đề liên quan