Draft JEP: Derived Record Creation (Preview)

Remi Forax forax at univ-mlv.fr
Wed Jan 24 20:19:38 UTC 2024


Hello Gavin,
nice job, some small remarks.

> "The derived instance creation expression ... is logically equivalent to the following switch expression".

This is not stricto-sensu true because the switch expression exhaustiveness allows remainder. For example, the switch expression allows "oldLoc" to be a sealed super type of Point, but not the derived instance creation.

> "If the left-hand side of the assignment is an
unqualified name, that name must be either that of one of the component
variables, or that of a local variable that is declared within the transformation block."

Does this propagate to lambdas/local classes defined inside the transformation block ? I hope not.

> "... If it is empty then the result of the derived instance creation
expression is a _copy_ of the value of the source expression (the expression on
the left-hand side)" 

I would remove the example after that paragraph because Record::equals() has its semantics defined in terms of call of the canonical constructor (see the javadoc), so instead of having the spec depending on equals() depending on the canonical constructor. I think it's better to skip using equals() as an intermediary and defined that the copy is the result of a call to the canonical constructor with all the record component value extracted from the accessors.


And as a general remarks, I hope there will be a following JEP about record instance creation that allows to use the syntax of a transformation block to initialize a record.
Because as this have been already discussed on several mailing list, if we only give the derived instance creation syntax, people will twist it to be able to initialize a record by component names, by adding an empty constructor that does nothing on the record. Defeating the idea that constructors should ensure that an invalid instance is not possible to create.

regards,
Rémi


----- Original Message -----
> From: "Gavin Bierman" <gavin.bierman at oracle.com>
> To: "amber-spec-experts" <amber-spec-experts at openjdk.org>
> Sent: Wednesday, January 24, 2024 6:16:33 PM
> Subject: Draft JEP: Derived Record Creation (Preview)

> Dear Spec Experts,
> 
> We have discussed on this list a new `with` expression form to derive new record
> values from existing record values. A draft JEP for this feature is now
> available:
> 
> https://bugs.openjdk.org/browse/JDK-8321133
> 
> Please take a look at this new JEP and give us your feedback (either on this
> list or directly to me).
> 
> Thanks,
> Gavin


More information about the amber-spec-experts mailing list