假设我定义了一些消息:
sealed trait Command
case class A(i: Int) extends Command
case class B(str: String) extends Command
然后是下面的经典演员来处理这些消息。在创建时,我需要访问 ActorContext 但作为类型化上下文而不是经典
class MyActor extends Actor {
val typedContext: ActorContext[Command] = ???
def receive = {
case A(i) =>
// Do something with i
case B(str)
// Do something with str
}
}
我知道我可以做 self.toTyped[Command] 来获取输入的自我引用。但我找不到任何与 ActorContext 类似的东西。我将如何进行转换?