我运行了以下代码:
scala> var s = new Stack()push(1)
s: scalatest.Stack[Int] = 1
scala> s match { case s : Stack[String] => print("Hello")}
<console>:12: warning: non variable type-argument String in type pattern scalatest.Stack[String] is unchecked since it is eliminated by erasure
s match { case s : Stack[String] => print("Hello")
}
Stack 是取自http://www.scala-lang.org/node/129的类。如果我在没有-unchecked
标志的情况下运行此代码,它将打印“Hello”。为什么会这样?