Records -- current status
brian.goetz at oracle.com
Tue Mar 20 13:33:34 UTC 2018
You can certainly use this to clone (that's what the clone() impl would
do), but its not as convenient to do it manually. Using getters:
new Address(addr.first(), addr.last(), addr.street(), addr.city(),
is more cumbersome than "addr.clone()". Similarly:
let Addr(var f, var l, var s, var c, var p) = addr;
new Addr(f, l, s, c, p);
is worse. Both are repetitive, harder to read, and error-prone.
The motivation for unleashing a parallel construction deconstruction
(and jiggering the rules so that composing them is an identity) is what
enables safe mechanical serialization of all forms (not just java.io
serialization.) But just because the tools are now in the users hands,
doesn't mean we shouldn't give them help.
I find clone very useful for arrays (covariant returns made clone() a
lot more useful.) I could imagine it being equally useful for records.
On 3/20/2018 8:26 AM, Remi Forax wrote:
> There is no need to have a clone because clone ==
> And this is true for the serialization too, once you have a
> de-constructor and a constructor you can serialize the data in the
> middle, as you can do a shallow copy or a deep copy in the middle.
More information about the amber-spec-experts