JEP draft: Universal Generics (Preview)

submited by
Style Pass
2021-06-09 15:30:08

Allow Java type variables to range over both reference types and primitive value types. Produce warnings when a type variable or a primitive value type might be assigned null. This is a preview language feature.

The core primitive value types feature is introduced in JEP 401. This JEP is only concerned with supporting primitive value types as type arguments.

In the future, we expect the JVM to optimize the performance of primitive value type parameterizations, with help from the Java compiler. But for now, generics continue to be implemented via erasure.

Significant adjustments to generic standard library code are expected in response to these language changes, but those adjustments will be pursued in a separate JEP. Future work may also refactor implementations of hand-specialized primitive code.

A common programming task is to take code that solves a problem for values of a particular type and extend that code to work on values of other types. Java developers can use three different strategies to perform this task:

Leave a Comment