为什么不在运行时指定Java通用类型参数? [英] Why aren't Java generic type parameters reified at runtime?
问题描述
允许新代码与旧代码进行交互。 b
$ b
从类型擦除
$ b
类型擦除使Java应用程序
能够使用泛型来维护二进制
与在
泛型之前创建的Java库和
应用程序的兼容性。
[...]
类型擦除存在,因此新代码
可能会继续与传统
代码接口。
有关相关问题,请查看 C#vs Java泛型。
My understanding is that C# and java differ with respect to generics in some ways, one of which is that generic type parameters are available at runtime in C#/.NET but not in Java. Why did the Java language designers do it this way?
To allow binary compatibility with pre-generics bytecode, therefore allowing new code to interface with old code.
From the Type Erasure page of The Java Tutorials:
Type erasure enables Java applications that use generics to maintain binary compatibility with Java libraries and applications that were created before generics.
[...]
Type erasure exists so that new code may continue to interface with legacy code.
For a related question, take a look at C# vs Java generics.
这篇关于为什么不在运行时指定Java通用类型参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!