JEP 401 has moved to Candidate status: a major Project Valhalla milestone. 🎉
It proposes value objects: immutable objects defined by their data, without a unique identity.
⚠️ This is still a preview proposal; not a feature available in ordinary production Java today.
🔸 TL;DR
Value classes aim to combine object-oriented modelling with performance characteristics closer to primitives.
🔸 1. DECLARING A VALUE RECORD
value record Point(int x, int y) {}
Point keeps the abstraction of a class, but its instances are immutable and interchangeable. Its fields and the record itself are implicitly final.
🔸 2. COMPARING FIELD VALUES WITH ==
var p1 = new Point(17, 3);
var p2 = new Point(17, 3);
System.out.println(p1 == p2); // true
For value objects, == checks whether objects are indistinguishable from their field values; not whether two references point to the same identity.
⚠️ equals() still matters: logical equality may differ from exact field-by-field indistinguishability.
🔸 3. MODELLING AI-FRIENDLY NUMERIC DATA
value record QuantizedWeight(byte value) {}
QuantizedWeight[] weights = {
new QuantizedWeight((byte) 12),
new QuantizedWeight((byte) -7)
};
This could provide expressive domain types for quantized weights, coordinates or specialized numeric values while giving the JVM freedom to flatten or scalarize them.
That can mean fewer heap allocations, better memory locality, lower GC pressure and more cache-efficient processing.
However, JEP 401 enables these optimizations; it does not guarantee a particular memory layout.
🔸 TAKEAWAYS
▪️ Value objects are immutable and have no identity.
▪️ value class and value record are explicit opt-ins.
▪️ Synchronization and other identity-sensitive operations are unsupported.
▪️ Arrays and fields may become flatter and more cache-friendly.
▪️ This could benefit data-intensive and AI workloads.
▪️ JEP 401 is Candidate and Preview: experiment, but do not assume production availability yet.
Java is preparing for the AI world without abandoning its object model. ☕🤖
#Java #OpenJDK #JEP401 #ProjectValhalla #JVM #JavaPerformance #AI #GarbageCollection #SoftwareArchitecture
JEP401: https://openjdk.org/jeps/401
Go further with Java certification:
Java👇
Spring👇
SpringBook👇
JavaBook👇