OpenJDK proposals would bring universal generics to Java
Java would get universal generics as part of the OpenJDK proposals to make the language easier to use, although the plan itself would take years to materialize.
Universal generics would be delivered initially through three proposals floating in the OpenJDK community. Together, the proposals would radically change the Java language and the JVM, combining class flexibility and primitive performance, according to Oracle. Everything, including the primitives, would become an object. But instead of making the primitives less efficient, the chosen path would make the classes as efficient as the primitives.
Each of the three JDK Improvement Proposals (JEP) offers different functionality, but all three would be necessary to achieve the expected benefits. Chief among these is a JEP project, created in February and updated on October 29, which calls for unifying the treatment of reference and primitive value types in generic code by allowing Java type variables to s ‘expand on both types of types. New warnings would be produced to maintain the security guarantees of the generic code.
A second JEP, to improve the Java object model with primitive objects declared by the user, would serve as a prerequisite. A third JEP, to unify base primitives with objects, should also take place. Additional JEPs would follow to update standard libraries, handle null warnings and prepare for library specialization, and introduce generic API runtime specialization into the JVM.
The generic universal plan encourages generic APIs to directly support primitive value types, to work directly on custom primitives. Reference types would also be supported. This should ideally be the default behavior of Java generics, so that primitive value types can fully participate in the Java ecosystem, the proposal says. There is currently no date set for the appearance of universal generics in Java, but it would take several years to materialize.
Universal generics would extend the existing generic capabilities of the platform. Java 2 Platform, Standard Edition 5.0, introduced in 2004, brought generics to the language and the platform, allowing developers to identify what they want to store in a collection and to secure the type of iterators. But with the 2004 iteration of generics, developers could only generate on reference types. By unifying the primitives with references, a next step could be taken which allows type parameters to be distributed across all types.
Java isn’t the only language to consider generic capabilities these days. Google’s Go language is expected to add generics soon.
Copyright © 2021 IDG Communications, Inc.