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)。
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)”很好地进行交换。
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)”很好地进行交换。
应用推荐