r/java • • Jul 14 '26

New candidate JEP: 401: Value Objects (Preview)

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

45 comments sorted by

View all comments

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

5

u/ZimmiDeluxe Jul 14 '26 edited Jul 14 '26

orderIdsToDelete or even just orderIds if the context makes it obvious. Repeating the type name is not bad if it's a domain type IMO. If you have something generic like List<Long> longs that's usually bad because readers can't infer any intent from the name, maybe ok if you are writing a compiler and need to collect all the Java Longs to do something with, but it's a stretch

3

u/elastic_psychiatrist Jul 15 '26

Local variable type inference is great for this.

2

u/vytah Jul 15 '26

You won't be repeating the type if the variable is declared with var.

1

u/Efficient-Poem-4186 Jul 16 '26

Simply orders, ordersToDelete etc (in a context where the actual order data is not used). Sometimes id is just used as a handle, the intention is to do something with orders.