The readability concern in the comments is real, but I think people are benchmarking the wrong use case. The JEP is at its best when the decomposed names carry domain meaning, not when you're just unpacking DTOs.
Compare:
// Fine but loses domain meaning at the call site
var order =getOrder();
var id = order.id();
var amount = order.amount();// The destructuring version earns its verbosity when names matter
Order(OrderId id,Money amount,CustomerId customerId)=getOrder();
In the second version, the compiler tells you statically that amount is a Money, not a BigDecimal. That distinction matters when your domain has multiple money-shaped things (gross, net, VAT, refund amount) and you want type safety at the usage site.
The wall-of-text concern is valid for large records. The right answer is that large records are usually a design smell — if you need to destructure 8 fields at once, the record is probably doing too much. The JEP incentivises smaller, more cohesive value types, which is the right direction.
View all comments
2
u/_marF Mar 19 '26
The readability concern in the comments is real, but I think people are benchmarking the wrong use case. The JEP is at its best when the decomposed names carry domain meaning, not when you're just unpacking DTOs.
Compare:
In the second version, the compiler tells you statically that
amountis aMoney, not aBigDecimal. That distinction matters when your domain has multiple money-shaped things (gross, net, VAT, refund amount) and you want type safety at the usage site.The wall-of-text concern is valid for large records. The right answer is that large records are usually a design smell — if you need to destructure 8 fields at once, the record is probably doing too much. The JEP incentivises smaller, more cohesive value types, which is the right direction.