The case for run-time types in generic Java

The case for run-time types in generic Java
复制标题

泛型 Java 中运行时类型的情况

DOI:
--
复制
发表时间:
2002
期刊:
PPPJ/IRE
影响因子:
--
通讯作者:
Robert Cartwright
Robert Cartwright
中科院分区:
--
文献类型:
--
作者:
Eric E. Allen;Robert Cartwright

文献摘要

被引文献

相似文献

自1995年Java编程语言出现以来,已经提出了许多深思熟虑的建议,以向Java编程语言添加泛型类型。泛型类型是现有语言中的一个明显遗漏,迫使程序员对“自然泛型”类(如java.util.Vector)的字段和方法使用许可的非参数类型签名,并重复地将这些类上的操作结果强制转换为更具体的类型。由Sun Microsystems提出的Java的JSR14扩展(基于GJ)通过向语言添加泛型类型来解决这个问题,但禁止依赖于运行时泛型类型信息的操作。这种禁止将泛型类型降级为“第二类”状态,即它们在运行时不可见,这与现有语言中包括参数数组类型在内的类型的状态不一致。我们已经实现了一个通用的JSR 14称为NextGen,支持相同的语法扩展的Java的JSR 14,但消除了禁止依赖于运行时泛型类型信息的操作。在下一代泛型类型是“第一类”:它们可以在与常规类型相同的上下文中使用。NextGen编译器的实现源自与JSR14编译器相同的原型GJ编译器,并共享其大部分理想属性,包括与遗留代码的高度兼容性。在本文中,我们通过一系列的编程实例表明,第一类泛型类型在编写干净的泛型代码中起着重要的作用。
Since the advent of the Java Programming Language in 1995, many thoughtful proposals have been made for adding generic types to the Java programming language. Generic types are a glaring omission from the existing language, forcing programmers to use permissive, non-parametric type signatures for fields and methods of "naturally generic" classes (such as java.util.Vector) and repeatedly cast the results of operations on these classes to the more specific types. The JSR14 extension of Java proposed by Sun Microsystems (based on GJ) addresses this problem by adding generic types to the language, but prohibits operations that depend on run-time generic type information. This prohibition relegates generic types to "second-class" status where they are invisible at run-time, which is inconsistent with the status of types including parametric arrray types in the existing language. We have implemented a generalization of JSR14 called NextGen that supports the same syntactic extensions of Java of JSR14 yet eliminates the prohibition on operations that depend on run-time generic type information. In NextGen. generic types are "first-class": they can be used in excactly the same contexts as conventional types. The implementation of NextGen compiler is derived from the same prototype GJ compiler as the JSR14 compiler and shares most of its desirable properties including a high degree of compatibility with legacy code. In this paper, we show through of a series of programming examples that first-class generic types play an important role in writing clean generic code.