我有一个演员向另一个演员发送消息。它还创建了另一个actor,并且在编译时不知道它的类型。在创建时,它需要添加一个mixin。我想知道如何在语法上解决这个问题。例如,如果我们有:
trait MyMixin extends Actor {
abstract override def receive = {
case msg =>
// Do something
super.receive(msg)
}
}
class Sender(targetClass: Class) extends Actor {
// Here I want to create the actor such that I can add the mixin
// eg. If I knew the class at compile time I could do the following:
// val target = context.actorOf(Props(new TargetActor with MyMixin))
val target = context.actorOf(Props(???))
target ! someMsg
...
}
所以问题是如何将这两个类组合起来进行运行时创建?
由于 DES