When I need to pass typed collections to an actor, I get an “unchecked” warning in my react method:
val actor = actor {
loop {
react {
case a:List[String] => // do something
}
}
}
How can I work around this? I tried boxing collection in a separate class (but that is ugly and cumbersome), and just casting collection (case a:List[_] => a.asInstanceOf[List[String]]) after receiving it by actor is not type-safe and dangerous.
Because the JVM does not keep track of the type of generics, you can’t know that a
List[_]is aList[String]unless you examine every element and check that it is a string. Your best bet is in fact to box the collection in a separate class. It need not be so bad!