Draft JLS spec for records

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Sep 3 12:02:22 UTC 2019

> De: "Gavin Bierman" <gavin.bierman at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 3 Septembre 2019 12:37:17
> Objet: Re: Draft JLS spec for records

> Thanks Remi.

>> - a canonical constructor can not have throws clause (from the text of the
>> section) but the grammar in 8.10.2 the CompactConstructor declaration can have
>> a throw clause ?

> That is just a typo - thanks. The rest I will get back to you shortly.

thinking more about the canonical constructor 
- does'nt really need a modifier (it's always public if you believe the current state of the spec or it's the one of the record anyway) 
- doesn't need to declare a type parameter 
- doesn't need annotations because you get the one from the record 
so it's more like an initializer than a constructor. 

Given that i've always find the syntax of the canonical constructor too close to the one of the real constructor (depending on the fact that parenthesis are present or not), 
i propose a new kind of initializer, the require initializer (obvisouly it can be another name than "require"). 

An example of syntax: 
record Foo(String s) { 
require { 

I also believe we should make the instance initializer illegal in record given that a require initializer is a kind a better instance initializer because it can access local variables. 

An example that should not compile 
record Foo(String s) { 
require { 
System.out.println("am i print first ?"); 
System.out.println("am i print first ?"); 

> Thanks,
> Gavin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20190903/b836c2a5/attachment.html>

More information about the amber-spec-experts mailing list