我有以下课程:
class MessageProcessorActor(private val destination : ActorRef) extends Actor{
override def receive: Receive = {
case _ =>
destination ! {
case MyActor.TracableMessage(msg) => MyActor.TracableMessage("Processed + " + msg)
case MyActor.Message(msg) => MyActor.Message("Processed + " + msg)
case _ => "Processed + " + _
}(_)
}
}
object MyActor{
case class TracableMessage(private val msg: String) extends Message(msg)
case class Message(private val msg: String)
}
其中Recieve
定义为
type Receive = PartialFunction[Any, Unit]
在这里,我试图避免声明val
持有PartialFunction[Any, Any]
并以这种方式调用它。但编译器拒绝此代码。它打印:
Error:(12, 6) ';' expected but '(' found.
}(_)
^
有没有捷径可以做这样的事情?