I want to get rid of type erasure warnings of this sample code:
val a: Seq[Any] = Seq(1)
a match {
case b: Seq[Int] => b.map(c => println(2 * c) )
case _ => println("Not matched")
}
It compiles and works ok, but with a warning:
Warning:(31, 13) non-variable type argument Int in type pattern Seq[Int] (the underlying of Seq[Int]) is unchecked since it is eliminated by erasure case b: Seq[Int] => b.map(c => println(2 * c) ) ^
Do you have any simple solution for avoiding the erasure in this case?
What have I tried so far (accorting to this):
val a: Seq[Any] = Seq(1)
a match {
case b@Seq(_:Int) => b.map(c => println(2 * c) )
case _ => println("Not matched")
}
But it won't compile because c is now of type Any.
I believe there are several solution to this problem. I will accept the simplest one.