TECH Signal 419
Project Valhalla's First Preview: JEP 401 Redefines == for Java Objects
JEP 401 adds a `value` modifier that creates identity-free classes with final fields and makes `==` perform deep value comparison.
Enabling the preview lets the JVM potentially scalarize or flatten small objects, lowering allocation and GC overhead. The feature is disabled by default and requires `--enable-preview` at compile and run time, plus recompilation to embed the new class-file attribute. APIs that depend on object identity, such as `java.lang.ref.Reference`, will reject value objects, so existing code may need adjustments.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
The `value` modifier defines classes whose fields are implicitly final and whose construction must complete before the instance is observable, and synchronized methods are prohibited.
`==` on value objects now succeeds when both operands have identical field values, while `equals` remains the recommended logical comparison.
The preview is off by default; enabling it requires compile-time and runtime flags, recompilation of affected classes, and breaks identity-based APIs like `Reference`.
THE READ
What the cluster adds up to.
JEP 401 has been merged into JDK 28 as a preview feature that introduces value objects, classes declared with a new `value` modifier. These classes differ from ordinary Java classes by having no identity, with all instance fields treated as final and required to be fully assigned before the object can be observed. The change is intended to let the JVM represent such objects without the usual heap allocation, reducing memory and GC costs. The language now enforces stricter construction rules: every field must be assigned during construction, and the bytecode verifier supplied by JEP 539 checks this at load time. Additionally, instance methods of a value class may not be synchronized, eliminating a source of hidden locks. Developers must add the `value` keyword to class definitions and adjust any synchronized methods accordingly. Equality semantics have been altered for value objects. The `==` operator, which previously compared only object references, now performs a recursive field-by-field comparison when both operands are instances of the same value class. This does not replace `equals`; the usual guidance to use `equals` for logical equality still applies because the internal re
Written by elseif from the cluster below · checked for specifics the sources never containedTHE CLUSTER
↗