给定以下功能:
scala> def foo(x: Any) = x match {
| case _: (String, Int) => "foo"
| case _ => "bar"
| }
我收到以下编译时警告:
<console>:8: warning: non-variable type argument String in type pattern (String, Int) is unchecked since it is eliminated by erasure
case _: (String, Int) => "foo"
^
foo: (x: Any)String
我对 JVM 擦除(即 for List[T]
)的理解是,在运行时,JVM 不知道T
.
请解释为什么上面is unchecked since it is eliminated by erasure
出现了在 2 元组上进行模式匹配的尝试。