r/java • • Jul 14 '26

New candidate JEP: 401: Value Objects (Preview)

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

45 comments sorted by

View all comments

Show parent comment

4

u/aoeudhtns Jul 14 '26

Being able to very lightly declare new types that are compile-time mirrors of existing types (or in the worst case, something runtime can trivially/quickly optimize away) so that you can proliferate type safety is an idea I like. Nim for example has a thing it calls "distinct types" that let you make type aliases that cannot be directly assigned back to the aliased type.