為什么Scala的不可變Set在其類型中不協(xié)變?根據(jù)原始答案重寫這個(gè)問題該scala.collection.immutable.Set班是不是在它的類型參數(shù)不變性。為什么是這樣?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}
為什么Scala的不可變Set在其類型中不協(xié)變?
FFIVE
2019-08-27 16:05:23