可能重複:
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")
}
棧是從http://www.scala-lang.org/node/129採取的類。如果我運行此代碼而沒有-unchecked
標誌,它將打印「你好」。爲什麼會這樣?
編譯器告訴你存在問題,它是什麼。你爲什麼在這裏問這個問題? – 2012-08-16 16:44:09