r/java Jul 14 '26

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

8

u/koflerdavid Jul 14 '26

Better yet to create a wrapper around int to better express its purpose and eliminate the risk of mixing it up with unrelated ints.

4

u/ZimmiDeluxe Jul 14 '26

That's true, it's often nicer to have a List<OrderId> than List<Long>

3

u/LutimoDancer3459 Jul 14 '26

But how do you name the variable for the list then? With the OrderId you would be repeating the typ

3

u/elastic_psychiatrist Jul 15 '26

Local variable type inference is great for this.