I understand generally what type erasure is and why we would encounter unchecked warnings. However, I don't understand why only one unchecked warning is issued in the following case:
class A[K] {
def receive: PartialFunction[Any, Unit] = {
case ds: List[Double] => // unchecked warning
println("* List[Double]")
case kx: Vector[K] => // no unchecked warning
println("* Vector[K]")
}
}
object TestApp extends App {
val a = new A[Int]
a.receive(List("bar"))
a.receive(Vector("foo"))
}
Both receive calls unfortunately match case clauses. Compiler did issue an warning for the first clause:
Warning: non-variable type argument Double in type pattern List[Double] is unchecked since it is eliminated by erasure.
I know TypeTag[T] can be used to achieve better type safety. But my concern here is why no unchecked warning is issued for the second case clause. As far as I think, type argument K is also erased and according to Java Generics FAQ
"unchecked" warnings are also reported when the compiler finds a cast whose target type is either a parameterized type or a type parameter
So I wonder why isn't there an unchecked warning?