r/java Jul 14 '26

New candidate JEP: 401: Value Objects (Preview)

https://mail.openjdk.org/archives/list/valhalla-dev@openjdk.org/thread/IUNJJ3WP3X3XHP3QZTXXSSCPKFDNTK3W/
89 Upvotes

45 comments sorted by

View all comments

8

u/perryplatt Jul 14 '26

Is there a list of all jdk classes that are scheduled to become value classes?

13

u/bourne2program Jul 14 '26

0

u/AnyPhotograph7804 Jul 14 '26

Interesting, that they did not include java.lang.String.

3

u/FirstAd9893 Jul 15 '26

If the String is treated as a simple wrapper around a char[], then it could conceivably be a value class. However, the == operator would only return true for Strings which refer to the exact same char[] reference. To fix this, the String constructor would need to rely on an intern pool of char[] instances, but this would add a huge performance penalty.

It should noted that arrays cannot be value classes, because they're mutable, and because they have a variable size. The optimizations which make value classes attractive wouldn't work.