1
我試圖按項目類型過濾列表。工作代碼是在這裏:定義按類型過濾來自列表的項目的方法
trait Action
class AAA extends Action
class BBB extends Action
val list = List(new AAA, new BBB, new AAA)
def find[T <: Action] = list.filter(_.isInstanceOf[T])
find[AAA]
預期它不工作,看到輸出:
scala> def find[T <: Action] = list.filter(_.isInstanceOf[T])
<console>:11: warning: abstract type T is unchecked since it is eliminated by erasure
def find[T <: Action] = list.filter(_.isInstanceOf[T])
^
find: [T <: Action]=> List[Action]
scala> find[AAA]
res0: List[Action] = List([email protected], [email protected], [email protected])
如何解決呢?
'erasure'已被棄用。 0'。 – senia