gpt4 book ai didi

Scala 案例类在接收方法中不匹配(在 akka Actor 中)

转载 作者:行者123 更新时间:2023-12-04 23:18:27 26 4
gpt4 key购买 nike

我有这样的事情:

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 上找到了答案。 :

I think the underlying misconception is about the identity of nested class types.

In

class A { class B }

each new instance of class A x creates a new type x.B. And if you do the plain pattern match inside of A you are referring to the specific instance of the type B this.B.

关于Scala 案例类在接收方法中不匹配(在 akka Actor 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34061968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com