-2

I have a case class defined in a scala companion object.

case class ResponseSuccess(resp: SMPPSubmitSMResp)

Which I send to an akka-actor (Java)

if(res.isRight) sender ! Backend.ResponseSuccess(sms.resp)

It is received like this, but I don't know how to extract the SMPPSubmitSMResp from the ResponseSuccess

} else if (msg instanceof Backend.ResponseSuccess) {
        SMPPSubmitSMResp packet = (SMPPSubmitSMResp) msg;
        someFunc(packet);
}

the error I get (i.e. the message is received) is:

Backend$ResponseSuccess cannot be cast to SMPPSubmitSMResp
FelixHJ
  • 1,071
  • 3
  • 12
  • 26

1 Answers1

3

If you use Scala, good approach to use Scala Pattern Matching:

msg match {
  case ResponseSuccess(resp) => // do something
  case _ => // do something else
}

If you want use Java, you will get a lot of cases where you have to cast objects especially for akka, so you can implement some utility for yourself. Something like this

Rinat Tainov
  • 1,479
  • 2
  • 19
  • 39