OpenJDK proposal would bring value classes and objects to Java

By Paul Krill

An OpenJDK proposal would preview value classes and objects in a forthcoming version of Java. The feature would provide Java class instances that have only final fields and lack object identity.

The Java enhancement proposal, which dates back to August 2020, was updated on June 21. The plan would allow developers to opt into a programming model for simple values in which objects are distinguished by their field values, much as the int value 3 is distinguished from the int value 4. A second goal is to migrate popular classes that represent simple values in the JDK, such as Integer, to this programming model. This is intended support compatible migration of user-defined classes. A third goal is to maximize the freedom of the JVM to encode simple values in ways that improve memory footprint, locality, and garbage collection efficiency.

The proposal is slotted as a preview language and JVM feature. It currently does not state a targeted version number for Java. It is not a goal of the plan to introduce a struct feature in the Java language. Java would continue to operate on two kinds of data, namely objects and primitives. It also is not a goal to change the treatment of primitive types or to automatically treat existing classes as value classes.

© Info World