我正在尝试按项目类型过滤列表。工作代码在这里:
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(AAA@2b9cbeec, BBB@3fba8e52, AAA@70d5ca2d)
如何解决?