Suppose, I send a request to an actor and receive its response synchronously:
case class MyRequest()
case class MyResponse(data:Any)
val resp = myActor !? MyRequest()
Now I have to downcast resp to MyResponse to access data
val data = (resp.asInstanceOf[MyResponse]).data
How can I git rid of the casting and write the code in a type safe manner? (I guess I can use pattern matching instead but I would prefer another solution).
As far as I know Scala Actors aren´t typed. So use Akka actors, which support typed actors. I also encountered your problem before and have handeled it with implicit manifest to get some kind of typed actors in scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With