I understand the JVM cannot distinguish at runtime between a List[String] and a List[Int] because of type erasure. But I wonder why do we only get a warning instead of a compiler error? For example,
List(1,2,3).isInstanceOf[List[String]] == true // warning: fruitless type test: a value of type // List[Int] cannot also be a List[String]
However, if I implement an overloaded method that takes either a List[Int] or a List[String], then I get a compile-time error, e.g.
def foo(xs: List[Int]): String = ??? def foo(xs: List[String]): String = ??? // error: double definition [foo] and [foo] have the same type after erasure