编辑 : 根据原来的答案重写这个问题
scala.collection.immutable.Set
类在其类型参数中不是协变的。为什么会这样?
import scala.collection.immutable._
def foo(s: Set[CharSequence]): Unit = {
println(s)
}
def bar(): Unit = {
val s: Set[String] = Set("Hello", "World");
foo(s); //DOES NOT COMPILE, regardless of whether type is declared
//explicitly in the val s declaration
}