We'll discuss type erasure in more detail in Chapter 12, The Scala type System.
我们会在《第12章-scala类型系统》详细讨论类型消除。
With type erasure, generic types are used for type checking only; afterwards, they are replaced with their upper bound.
使用类型消除(type erasure),泛型类型仅用于类型检查;然后,用它们的上界替换它们。
You'll get a compilation error on the second method because the two methods will have an identical signature after type erasure.
你会在第二个方法处得到一个编译错误,因为这两个方法在类型消除后拥有一样的签名。
Because Tiger relies on type erasure, the naked type parameters in casts and instanceof tests are "erased" to their upper bounds (in the earlier case, that'll be type Object).
因为Tiger依靠类型擦除,所以数据类型转换和instance of测试中的外露类型参数被“擦除”为它们的上界(在前面的例子中,那将是类型Object)。
However, there is an exception to this rule due to type erasure, which is a feature of the JVM only, but is used by Scala on both the JVM and.net platforms, to minimize incompatibilities.
不过,这里有一个由类型消除引起的例外,这是一个JVM的特性,但是被Scala在jvm和。NET平台上所利用从而最小化兼容问题。
Another consequence of erasure is that using casts or instanceof with generic type parameters doesn't make any sense. The following code will not improve the type safety of your code at all.
擦除的另一个后果是,对泛型类型参数是用强制类型转换或者instance of毫无意义。
Function types are indeed the natural way to represent the type of a lambda expression, but unfortunately they interact badly with an existing language "feature" : erasure.
函数类型确实是表现lambda表达式类型的一种自然方法,但遗憾的是它们无法与现有语言功能“擦除(erasure)”很好地进行交换。
We can force the erasure to be different, by explicitly specifying a superclass in the bound for the formal type parameter t.
我们可以迫使擦除湿不同的,通过显示的在形式参数t的边界中指定一个超类。
We can force the erasure to be different, by explicitly specifying a superclass in the bound for the formal type parameter t.
我们可以迫使擦除湿不同的,通过显示的在形式参数t的边界中指定一个超类。
应用推荐