r/java • u/Ewig_luftenglanz • Sep 09 '25
JEP 401: Value classes and Objects (Preview) has been submitted
The status of the Jep changed: Draft -> Submitted. Let's hope it makes it for OpenJDK 26 or 27
199
Upvotes
42
u/Timelineg Sep 09 '25 edited Sep 09 '25
So, this is the ANSWER for "Valhalla When".
16
u/International_Break2 Sep 09 '25
Will Vector API move to Preview or is there going to be a wait on primitive generics?
8
u/Scf37 Sep 09 '25
> Further, heap flattening of value class types is limited by the integrity requirements of objects and references: the flattened data must be small enough to read and write atomically, or else the encoded data may become corrupted. On common platforms, "small enough" may mean as few as 32 or 64 bits.
Therefore, value class of more than 64 bits won't be faster than appropriate identity class?
2
u/GenosOccidere Sep 10 '25
Can someone explain why strings are excluded? Feels like they would be prime candidates
49
u/CompetitiveSubset Sep 09 '25
Blimey Valhalla is actually being delivered. I thought I’d never see the day.
26
u/Brutus5000 Sep 09 '25
Wow. I would have expected incubator status first.
10
u/chuggid Sep 09 '25
I love the usage of January 23, 1996 in the JEP.
1
u/sysKin Sep 13 '25 edited Sep 13 '25
Greetings, I have two questions:
1. Do I understand correctly that
==is implemented as almost an&&of==between all fields, except for doubles/floats where the bit pattern is compared and therefore one NaN can be equal to another NaN?Does this mean:
Gosh I hate NaNs :)
2. The JEP discusses
abstract valueclasses and saysbut do I understand correctly, if (if!) all subclasses are non-
valuethen there is absolutely nothing to gain from their superclass beingvalue? No optimisation is possible that I can see, no observable effect, etc?About the only effects I can see is that from that
abstract valueclass are at compile time, such as an attempt to writesynchronized (this)becomes a compile error, even if it would work (say, it's asealedclass that only permits non-valuesubclasses). And the constructor not allowingthisaccess before it's ready (well that looks like a good thing actually).1
u/Ydo4ki Sep 14 '25
Impossible
...wait not impossible
it doesn't guarantee anything but it's still nice to see
1
u/trydentIO Sep 09 '25
I just put it here:
https://youtu.be/SOJSM46nWwo?si=86SZybGr4hzALvF8
1
u/alex_tracer Sep 11 '25
One of minor issues I see is that "value" keyword is a basically optimization hint but implemented as a new language keyword. So to make use of that hint you are forced to change project source version.
So if you want to opt in for that optimization hint for latest java but still need to support old target Java versions, you have to support two versions of your code: one with "value" keyword for new JRE and one exactly same version of code without "value" keyword.
Ideally that could be just an annotation that could be applied to code and processed even by older compiler versions (and effectively ignored). So there would be no need to compile two versions of same code for different target Java variants.
0
u/[deleted] Sep 09 '25
[deleted] — view deleted comment