为什么这个函数不能编译?
case class MyType(n: Int) def intersection(s1: Set[MyType],s2: Set[_ <: MyType]) = (s1 & s2)
我收到以下错误:
error: type mismatch; found : Set[_$1] where type _$1
<: MyType required: scala.collection.GenSet[MyType] Note: _$1 <:
MyType,but trait GenSet is invariant in type A. You may wish to
investigate a wildcard type such as_ <: MyType
. (SLS 3.2.10)
(w & r)
是否有一种简单的方法可以“提升”第二个参数来键入Set [MyType]而不使用asInstanceOf?