Re:Java 21: What’s New?
by brap on Wednesday August 09, 2023 @04:47PM
(#37068159)
Thanks I hate it
[ Parent
| on HN ]
You hate that it takes 2 lines instead of 4 (excluding curly braces) to accomplish the same? The new syntax is not even convoluted, it's pretty intuitive destructuring syntax already available in many modern languages.
There's potential confusion whether the int x from the example comes from point.x (field), point.x() (method) or point.getX() (common getter pattern), just one more gotcha
By reading the proposal [1], I see it's meant for record types. Records seem to be value classes, i.e. the equivalent to Scala's case classes.
In that case, there's absolutely no ambiguity: there's only one `x` you can be talking about.
By the way, value/case classes are such a boon. Very easy to get used to, and once you have, you want to use them everywhere, I guarantee.
----