0

I have a case block that contains the following case blocks:

def method(...) = x match {
  case xyz: (List[String], TypeA, TypeB) => ...
  case abc: (TypeA, TypeB) => ...
}

For the above code, I get a warning non-variable type argument List[String] in type pattern (List[String], TypeA, TypeB) is unchecked since it is eliminated by erasure.

I understand that the compiler cannot see the difference between List[String] or List[Int] or List[T] in the case block, but how do I get rid of these warnings?

joesan
  • 13,963
  • 27
  • 95
  • 232
  • 3
    How to get around type erasure in Scala: 1) spend an hour thinking about how you can solve the problem some other way; 2) Google "getting around type erasure in Scala". – Travis Brown Aug 26 '14 at 14:38
  • Repeat at least the first step the next time you run into the issue. – Travis Brown Aug 26 '14 at 14:39
  • For me it's: 1) Google "getting around type erasure in Scala" 2) Forget everything about it afterwards. Repeat. – Kigyo Aug 26 '14 at 15:53
  • For me it's: 1) answer someone's dupe about "getting around erasure" 2) forget it and 3) need it, remember vaguely that I answered it on SO, then search on my answers (which hopefully wasn't deleted as duplicate, otherwise goto step 1 because there's always another). – som-snytt Aug 26 '14 at 15:58
  • This may not be a duplicate if the question is really "how do I hide/disable these warnings?". Is that what you're after, or do you actually want a type-safe match? – Aaron Novstrup Aug 26 '14 at 16:20
  • I resolved it by using type alias. – joesan Aug 27 '14 at 08:16

0 Answers0