Minor improvement to anonymous classes

Remi Forax forax at univ-mlv.fr
Sat Jul 31 18:29:05 UTC 2021


> From: "John Rose" <john.r.rose at oracle.com>
> To: "Tagir Valeev" <amaembo at gmail.com>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Sent: Samedi 31 Juillet 2021 20:00:20
> Subject: Re: Minor improvement to anonymous classes

> On Jul 30, 2021, at 8:55 PM, Tagir Valeev < [ mailto:amaembo at gmail.com |
> amaembo at gmail.com ] > wrote:

>> 2. Allow new {...} instead of new Object() {…}.

> I would think *that* would make a very useful poly expression.
> Building “new Object() {…}” has far fewer use cases than
> “build me an object of the type the context requires, with
> these methods”.

> My overall reaction to the extra syntax tweaks to the
> existing AIC syntax is, “meh”. The syntax is inherently
> ceremonious; why trouble to elide an extra token at
> the head?

and i would prefer to keep that syntax available if at some point in the future we decide to allow classes (or perhaps just record) to be initialized in a literal way. 

record Person(String name, int age) {} 

var person = new Person { name = "Ana", age = 31 }; 
Person person = new { name = "Ana", age = 31 }; 

which is more readable once you starts to have more than 3 or 4 components (and avoid builders). 

Rémi 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210731/b34076be/attachment-0001.htm>


More information about the amber-spec-experts mailing list