3
为什么Scala的不可变集的类型不协变?
编辑:根据原始答案改写了这个问题 该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 }