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.