trait Aggregate {
type Command
}
class AggregateHandler(a: Aggregate) {
def receiveCommand: Receive = {
case a.Command => ???
}
}
如何在a.Command上进行模式匹配?我正进入(状态; abstract type pattern AggregateHandler.this.a.Command is unchecked since it is eliminated by erasure
和The outer reference in this type test cannot be checked at run time.
我该如何解决这个问题?
答案 0 :(得分:0)
例如,此Aggregate#A
有一个outer
字段,指向Aggregate
的封闭实例。
trait Aggregate {
//type A
class A
}
class AggregateHandler(a: Aggregate) {
def f: PartialFunction[Any, Unit] = {
case _: a.A => ()
}
}
object Test extends App {
class X extends Aggregate {
//type A = Int
val x: A = new A
}
val x = new X
val h = new AggregateHandler(x)
h.f(x.x)
}