Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of downcast using synchronous send with Scala Actors?

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).

like image 488
Michael Avatar asked Dec 08 '25 01:12

Michael


1 Answers

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.

like image 70
Peter Schmitz Avatar answered Dec 11 '25 13:12

Peter Schmitz