Updated Draft specs for JEP 359 (Records)

Brian Goetz brian.goetz at oracle.com
Sat Nov 2 13:19:33 UTC 2019


> Is it allowed to declare a canonical constructor explicitly and make
> it non-public?  I think the naswer is no.  But it's not quite obvious
> from the spec, I think.

No, it is not.  

The basic idea is that with a record, you’ve given up the right to decouple your API from the representation, which is declared in the header.  So you will get a public canonical constructor, accessors, state-based Object methods, and eventually, a deconstruction pattern.  You can “override” these methods, but subject to an invariant: “copying” a record (feeding the result of its accessors to its canonical actor) must be equals() to the original.   A record is the state, the whole state, and nothing but the state.  

> Will the canonical constructor be invoked upon deserialization?
> Sorry, I can't find a discussion of that aspect, but I'm sure it must
> have come up before.

Yes, this is in the serialization spec, not the language spec.  


More information about the amber-dev mailing list