Java's Valhalla: Value Objects & Redefined == (JEP 401)
Alps Wang
Aug 11, 2026 · 1 views
The Dawn of Value Objects
JEP 401, introducing value objects to Java, marks a pivotal shift in the JVM's object model, moving away from the pervasive identity-based semantics towards a more data-centric approach. The core innovation lies in the introduction of the value modifier, creating classes with final fields and identity-free instances. This fundamentally alters the behavior of the == operator for these objects, enabling it to perform value comparison rather than just reference identity checking. This is a crucial step towards enabling significant JVM optimizations, such as scalarization and flattening, which can drastically reduce memory allocations and improve cache locality. The implications for performance-intensive applications, especially those dealing with large numbers of small, immutable data structures, are substantial. Developers will likely see reduced garbage collection pressure and potentially faster execution.
However, this paradigm shift is not without its complexities and potential concerns. The preview nature of JEP 401 means it's not yet production-ready, and developers need to be mindful of the --enable-preview flag for both compilation and runtime. The restrictions on value classes, such as the inability to synchronize instance methods and stricter construction rules enforced by JEP 539, will require developers to adapt their coding patterns. Furthermore, the implicit redefinition of == for value objects, while powerful, could lead to confusion if not clearly understood, especially given that equals() remains the standard for logical equality in many contexts. The article rightly points out that == for value objects compares field values recursively, which is a powerful semantic change. The security considerations regarding potential exposure of private field values through == and identityHashCode, and the unbounded time for comparing large object trees, are valid points that warrant careful attention during wider adoption.
The primary beneficiaries of this change will be Java developers working on performance-critical applications, embedded systems, or any domain where the overhead of traditional object identity is a bottleneck. This includes areas like game development, financial trading platforms, and scientific computing. The ability to represent data more compactly and efficiently could also lead to more sustainable cloud deployments by reducing memory footprints. While the article mentions that migration effects for several value-based JDK classes are expected, and some APIs like Reference will throw IdentityException for value objects, this highlights the necessary breaking changes that often accompany foundational language evolution. The long-term impact hinges on the JVM's ability to effectively leverage these new value object semantics for optimization, which, as the article notes, is an expected payoff rather than a guaranteed benchmark result, especially during the initial warmup phases.
Key Points
- JEP 401 introduces 'Value Objects' to Java, a preview feature in JDK 28 (Project Valhalla).
- Value objects have identity-free instances and implicitly final fields, designed for data-centric representation.
- The
==operator is redefined for value objects to perform value comparison (field-by-field) instead of just reference identity. - This enables JVM optimizations like scalarization and flattening, reducing memory allocation and GC pressure.
- Restrictions include no synchronized instance methods and stricter construction rules.
- Several JDK classes like primitive wrappers and
LocalDatemay become value classes in preview.

📖 Source: Project Valhalla's First Preview: JEP 401 Redefines == for Java Objects
Related Articles
Comments (0)
No comments yet. Be the first to comment!
