3 ms·
This will be solved[1]: record Point(int x, int y) {} Point p = new Point(1, 2); Point pp = p with { x = 3; } [1] https://github.com/openjdk/amber-docs/blob/
by BoyRobot777 5y ago
This will be solved[1]:
record Point(int x, int y) {}
Point p = new Point(1, 2);
Point pp = p with { x = 3; }
[1] https://github.com/openjdk/amber-docs/blob/master/eg-drafts/reconstruction-records-and-classes.md https://github.com/openjdk/amber-docs/blob/master/eg-drafts/...
- stickfigure 5y agoInteresting. It's ok. It seems like they're adding this syntax just to avoid extra copies eg, `p with {x = 3, y = 4}` instead of `p.withX(3).withY(4)`. I really don't mind the later. My gut feel is that records break encapsulation and will make refactoring slightly more difficult than the equivalent lombok value class. But if this gets more people making objects immutable, I'm all for it.
- samus 5y agoThe perfect transparency of the underlying data is rather the whole point of records. Tempered by immutability, records should be a useful tool for modeling data where encapsulation is not required. Note that it is still possible to add methods that can perform computation on the underlying data.