[records] Non-compact canonical constructors

Brian Goetz brian.goetz at oracle.com
Sun Nov 10 15:43:55 UTC 2019

> Several points are unclear to me
> 1. It's not explicitly specified whether an explicitly declared
> canonical constructor must be 'public' like it's specified for compact
> constructors. Does this mean that I can declare non-public canonical
> constructor?

The compact constructor _is_ a canonical constructor; its just an alternate notation for it, and its an error to declare it both ways (because its an error to declare the same member twice).  The canonical constructor should be public (yes, Remi, we see you there), whether declared implicitly, explicitly with a full argument list, or explicitly with a compact ctor. 

> 2. I see the restriction for not having a return statement quite
> arbitrary. I understand it for compact constructors but see no reason
> for this restriction in non-compact canonical constructors. Could
> anybody provide a rationale behind this restriction? Sorry if it was
> discussed; in this case, links to the discussion would also be
> appreciated.

Yes, it exists primarily for compact constructors and could be refined to mention only those.  

> 3. As it's already mentioned in 8.10.3, each record component implies
> an implicitly declared private final field. And as [2] says,
> "A blank final instance variable must be definitely assigned and
> moreover not definitely unassigned at the end of every constructor of
> the class in which it is declared". Thus "Every field corresponding to
> a record component of R must be definitely assigned and moreover not
> definitely unassigned..." part seems redundant as it's covered by
> normal constructor rules. Probably it's not harmful to specify this
> explicitly though.

Agreed.  Ordinary DA should cover this, though its reasonable to remind the reader that DA applies to implicitly declared final fields too.

More information about the amber-spec-experts mailing list