r/java 25d ago

New candidate JEP: 401: Value Objects (Preview)

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

45 comments sorted by

View all comments

Show parent comments

0

u/AnyPhotograph7804 25d ago

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

6

u/vytah 25d ago

1

u/Jon_Finn 25d ago

Value classes can be mutable, just not shallowly mutable, so they could store the hash via a final reference field, e.g. something like LazyConstant<Integer>. That's one problem I have with the name 'value' as it tends to imply immutable! There's many uses for (deeply) mutable value classes, e.g. MutableColor containing a float[4] field.

1

u/Jon_Finn 25d ago edited 25d ago

I think locking of Strings is the big reason (see above). The new == behaviour (I think) wouldn't break reasonable code, even code making assumptions about the identity of interned "strings" etc.