Scala生活中的一个可悲事实是,如果你实例化一个List [Int],你可以验证你的实例是一个List,你可以验证它的任何单个元素是一个Int,但不是它是一个List [ Int],可以很容易地验证:
scala> List(1,2,3) match {
| case l : List[String] => println("A list of strings?!")
| case _ => println("Ok")
| }
warning: there were unchecked warnings; re-run with -unchecked for details
A list of strings?!
Run Code Online (Sandbox Code Playgroud)
-unchecked选项将责任直接归咎于类型擦除:
scala> List(1,2,3) match {
| case l : List[String] => println("A list of strings?!")
| case _ => println("Ok")
| }
<console>:6: warning: non variable type-argument String in type pattern is unchecked since it is eliminated by erasure
case l …Run Code Online (Sandbox Code Playgroud) Scala(至少在JVM上)使用类型擦除来实现Java兼容性.这个功能被广泛 持有 ,以 吸.在JVM上解决这个问题很困难.
与JVM情况相反,.NET支持reified泛型.Scala的.NET实现是否使用它们?如果没有,可能,或者使用具体原因会出现什么问题?