【发布时间】:2012-08-12 17:29:19
【问题描述】:
可能重复:
How do I get around type erasure on Scala? Or, why can't I get the type parameter of my collections?
我运行了以下代码:
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”。为什么会这样?
【问题讨论】:
-
编译器告诉你有问题,是什么问题。你为什么在这里问这个?
标签: scala types type-erasure