1

In my Akka program I have an anonymous inner Actor (extra pattern) which internally waits for responses from storage actors who return a list of their respective domain object (i.e. List[MyDomain]).

The anonymous actor's receive block waits for the response like so:

def receive = {
    case a: List[MyDomain1] => originalSender ! a
    case b: List[MyDomain2] => originalSender ! b
}

The problem is that I get erasure warnings:

Actors.scala:46: non-variable type argument domain.MyDomain1 in type pattern List[domain.MyDomain1] is unchecked since it is eliminated by erasure

(and another warning for the second case statement above).

How can I resolve this without introducing another type to represent the response from my storage actors? It makes sense that they return a List of their domain.

Alex
  • 8,093
  • 6
  • 49
  • 79
  • possible duplicate of [How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?](http://stackoverflow.com/questions/1094173/how-do-i-get-around-type-erasure-on-scala-or-why-cant-i-get-the-type-paramete) – pagoda_5b Nov 19 '14 at 17:55
  • 2
    If all you need is to return the response to the original sender then you could just match `List [_]`, or use the two-argument form of `tell` so the response goes there directly. If you need to do different things with different types of list you will need to include more type information in the message, perhaps by wrapping different lists in different 1-element case classes. – lmm Nov 19 '14 at 18:06
  • If the number of types is finite and small then you could consider a wrapper case class for each type so that you then lose the erasure related issues. Something like `case class MyDomain1List(list:List[MyDomain1])`. – cmbaxter Nov 19 '14 at 19:25
  • If it makes sense that they return a "List of their domain", would it not also make sense that they respond with a message object that _contains_ a list of their domain objects? – Eric Zoerner Nov 19 '14 at 20:00
  • I guess I could argue a "container type" e.g. `ListOfXXX` would make sense; it's just another case class, but I wanted it to use lists :( Could option help here? – Alex Nov 19 '14 at 20:26

1 Answers1

0

I opted for otherActor.tell(msg, originalSender), which avoided having the anonymous actor brokering the responses.

Alex
  • 8,093
  • 6
  • 49
  • 79