Scala class case is not consistent in the receive method (in acc-accs)

I have something like this:

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")
  }
}

and I call it like this:

class Prober extends ProbeActor {
  val definite = ActorSystem("ProbeTest").actorOf(Props[ProbeActor], name = "probed")
  implicit val timeout = Timeout(5 second)
  val future = definite ? Probe("key")
}

I expect the text "Good probe: key"to be printed, but I get it "Bad probe: Probe(key)".

Note . If I put the case class Probeoutside, then it works fine.

+4
source share
2 answers

After searching more, I found the answer on scala-lang.org :

I think the main misconception concerns the identity of nested class types.

IN

class A {class B}

A x x.B. A, B this.B.

+6

Probe, ,

case probe: ProbeActor#Probe => println("Good probe: "+probe.messageKey)

, (, ) ; , , .

+2

Source: https://habr.com/ru/post/1618391/


All Articles