我有这样的事情:
class ProbeActor extends Actor { case class Probe(messageKey: String) def receiveProbe: Receive = { case Probe(probeKey) => println("Good probe: "+probeKey) case x => println("Bad probe: "+ x) } final override def receive = receiveProbe orElse receiveOther def receiveOther: Receive = { case _ => println("Other") } }
我称之为:
class Prober extends ProbeActor { val definite = ActorSystem("ProbeTest").actorOf(Props[ProbeActor], name = "probed") implicit val timeout = Timeout(5 second) val future = definite ? Probe("key") }
我希望文本"Good probe: key"
应该打印,但我明白了"Bad probe: Probe(key)"
.
注意:如果我将Probe
案例类放在外面,那么它可以正常工作.
经过更多搜索,我在scala-lang.org上找到了答案:
我认为潜在的误解是关于嵌套类类型的身份.
在
A级{B级}
类A x的每个新实例都创建一个新类型xB如果你在A内部进行普通模式匹配,则指的是类型B this.B的特定实例.