object Test {
def main(args: Array[String]) {
val list: List[Double] = List(1.0, 2.0, 3.0, 4.0)
val none = None
case class Test()
val test = Test()
def f(x: Any) = x match {
case _: Some[Test] => println("_ matched")
case None => println("None matched")
}
f(list)
f(none)
f(test)
}
}
尝试编译上述代码会导致“被擦除消除”编译时警告。
$>scalac Test.scala
Test.scala:11: warning: non-variable type argument Test in type pattern
Some[Test] is unchecked since it is eliminated by erasure
case _: Some[Test] => println("_ matched")
^
one warning found
我阅读了这篇备受推崇的 Stackoverflow帖子,但我不明白这里的类型擦除。