Draft JEP: Derived Record Creation (Preview)
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Jan 25 13:13:22 UTC 2024
> From: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> To: "Remi Forax" <forax at univ-mlv.fr>, "Gavin Bierman" <gavin.bierman at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.org>
> Sent: Thursday, January 25, 2024 1:41:57 PM
> Subject: Re: Draft JEP: Derived Record Creation (Preview)
> Looking from another angle, I think an important distinction between creation
> and _derived_ creation is that in the latter case you have some "fallback"
> values to use if the `with` block doesn't specify transforms for all of them.
> In the plain creation case, since the object did not exist before, there is
> nothing to fall back to - other than the default value of course, which might
> be a surprising/lousy choice in some cases. So perhaps the similarity between
> these two cases is more superficial than it looks.
Let's take a look to the cousins of Java that have a syntax equivalent to the derived record creation. As far as i know, we have C# and Rust / Javascript.
In the case of C#, the syntax is very similar to the one proposed for Java, but the block of code uses '',' instead of ';' (*).
point with { x = 3, y = 4 }
The syntax for creating and initializing an object in C# is new Point { x = 3, y = 4 }.
As you can see the syntax is very similar.
In the case of Rust (or Javascript), the syntax uses a splat/spread operator at the end of the object initialization syntax,
Point {
x: 3,
y: 4,
..point // spread operator
}
In all cases, the same syntax is used for the creation and the derived creation. As you said, the semantics is slighly different but in an obvious way, the creation an object requires all components to be initialized, the derived creation don't.
regards,
Rémi
(*) given that the transformation block is just code in Java, it makes sense to use '=' and ';', given those are just variable assignments.
> Maurizio
> On 24/01/2024 20:19, Remi Forax wrote:
>> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20240125/baea8065/attachment-0001.htm>
More information about the amber-spec-experts
mailing list