<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Brian Goetz" <brian.goetz@oracle.com><br><b>À: </b>"Remi Forax" <forax@univ-mlv.fr>, "Tagir Valeev" <amaembo@gmail.com><br><b>Cc: </b>"amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Envoyé: </b>Jeudi 5 Septembre 2019 00:05:18<br><b>Objet: </b>Re: Draft JLS spec for records<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">Ideally, records are classes, with restrictions (like enums). And
again, ideally, we find the minimal set of restrictions (e.g., "no
instance fields"), and then we get out of the way. <br>
<br>
In the case of records, we have chosen to have a compact way to
declare the _canonical_ constructor. So they're not just classes
with restrictions, but classes with restrictions and small
enhancements. But ultimately, the less we depart from "records are
classes", the fewer special rules the user has to learn.<br>
<br>
Therefore, I don't think we should go out of our way to restrict, or
reinvent, instance initializers; I think "legal but rare" is a fine
place for this to be. </blockquote><div><br></div><div>yes,<br data-mce-bogus="1"></div><div>i agree,</div><div>"require" initializer does not worth the cost of making records different from classes.<br></div><div>so long live the compact constructor, i suppose :)<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><br>
<br>
<br>
<div class="moz-cite-prefix">On 9/4/2019 5:58 PM, <a class="moz-txt-link-abbreviated" href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>
wrote:<br>
</div>
<blockquote cite="mid:291999440.1577501.1567634297715.JavaMail.zimbra@u-pem.fr">
<div style="font-family: arial, helvetica, sans-serif; font-size:
12pt; color: #000000">
<div><br>
</div>
<div><br>
</div>
<hr id="zwchr">
<div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De:
</b>"Tagir Valeev" <a class="moz-txt-link-rfc2396E" href="mailto:amaembo@gmail.com" target="_blank"><amaembo@gmail.com></a><br>
<b>À: </b>"Remi Forax" <a class="moz-txt-link-rfc2396E" href="mailto:forax@univ-mlv.fr" target="_blank"><forax@univ-mlv.fr></a><br>
<b>Cc: </b>"Gavin Bierman"
<a class="moz-txt-link-rfc2396E" href="mailto:gavin.bierman@oracle.com" target="_blank"><gavin.bierman@oracle.com></a>, "amber-spec-experts"
<a class="moz-txt-link-rfc2396E" href="mailto:amber-spec-experts@openjdk.java.net" target="_blank"><amber-spec-experts@openjdk.java.net></a><br>
<b>Envoyé: </b>Mercredi 4 Septembre 2019 07:21:48<br>
<b>Objet: </b>Re: Draft JLS spec for records<br>
</blockquote>
</div>
<div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div dir="ltr">Hello!</div>
</blockquote>
<div><br>
</div>
<div>Hi !<br>
</div>
<div><br>
</div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div dir="ltr"><br>
<div>> 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.</div>
<div><br style="color:rgb(0,0,0);font-family:arial,helvetica,sans-serif;font-size:16px">
</div>
<div>I don't think so. A compact constructor (or require
initializer, as you propose) could be not the only
constructor. An instance initializer is convenient
because it's added to every constructor, regardless of
whether it's compact or not. So the new thing doesn't
supersede the instance initializer and I see no good
reason to explicitly disable it.</div>
</div>
</blockquote>
<div><br>
</div>
<div>I've forgotten that you can have multiple constructors in
a record too,<br>
</div>
<div>I never liked that a class can have multiple constructors
because it forces you to read the doc to choose between the
constructors and i'm too lazy for that :)<br>
</div>
<div><br>
</div>
<div>The problem with a record is that if you have multiple
constructors, you may mix classical constructors with the
compact one,<br>
</div>
<div>like this</div>
<div> record Foo(Object obj, int v) {<br>
public Foo(Object obj) {<br>
this.obj = obj;<br>
this.v = -1;<br>
}<br>
<br>
public Foo {<br>
Objects.requireNonNull(obj); // ensure obj is non
null<br>
}<br>
}<br>
</div>
<div><br>
</div>
<div>and i'm not sure that every readers will think seeing
this code that new Foo(null) is allowed,<br>
</div>
<div>and it will be worst if instead of a compact constructor
syntax we have an require initializer syntax because as you
said an instance initializer is copied in front of all
constructors.<br>
</div>
<div><br>
</div>
<div>I believe there are two ways to make sure a require
initializer is always executed,<br>
</div>
<div>either you specify that the require initializer is copied
in all constructors but if the constructors have different
parameters, you have to restrict the require initializer to
see only the common parameters which seems to magical for me
or you require explicit constructors to delegate to another
constructor, so the code above is not valid because the
first constructor doesn't call the canonical one.</div>
<div>The code has to be changed to</div>
<div> record Foo(Object obj, int v) {<br>
public Foo(Object obj) {<br>
this(obj, -1);<br>
}<br>
<br>
require {<br>
Objects.requireNonNull(obj); // ensure obj is non
null<br>
}<br>
}</div>
<div><br>
</div>
<div>regards,<br>
</div>
<div>Rémi<br>
</div>
<div><br>
</div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div dir="ltr"><br>
<div>With best regards,</div>
<div>Tagir Valeev.</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Sep 3, 2019 at
7:02 PM <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><br>
<br>
<hr id="gmail-m_-1709329539328181297zwchr">
<div>
<blockquote style="border-left:2px solid
rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>De:
</b>"Gavin Bierman" <<a href="mailto:gavin.bierman@oracle.com" target="_blank">gavin.bierman@oracle.com</a>><br>
<b>À: </b>"Remi Forax" <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>><br>
<b>Cc: </b>"Brian Goetz" <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>>,
"amber-spec-experts" <<a href="mailto:amber-spec-experts@openjdk.java.net" target="_blank">amber-spec-experts@openjdk.java.net</a>><br>
<b>Envoyé: </b>Mardi 3 Septembre 2019 12:37:17<br>
<b>Objet: </b>Re: Draft JLS spec for records <br>
</blockquote>
</div>
<div>
<blockquote style="border-left:2px solid
rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
<div>Thanks Remi.</div>
<div><br>
<blockquote>
<div>
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div> - 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
?<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>That is just a typo - thanks. The rest I
will get back to you shortly.</div>
</blockquote>
<br>
<div>humm,<br>
</div>
<div>thinking more about the canonical constructor<br>
</div>
<div>- 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) <br>
</div>
<div>- doesn't need to declare a type parameter<br>
</div>
<div>- doesn't need annotations because you get
the one from the record<br>
</div>
<div>so it's more like an initializer than a
constructor.<br>
</div>
<br>
<div>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),<br>
</div>
<div>i propose a new kind of initializer, the
require initializer (obvisouly it can be another
name than "require").<br>
</div>
<br>
<div>An example of syntax:</div>
<div> record Foo(String s) {<br>
</div>
<div> require {<br>
</div>
<div> Objects.requireNonNull(s);<br>
</div>
<div> }<br>
</div>
<div> }</div>
<br>
<div>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.<br>
</div>
<br>
<div>
<div>An example that should not compile<br>
</div>
<div> record Foo(String s) {</div>
<div> require {</div>
<div> System.out.println("am i print first
?");<br>
</div>
<div> }</div>
<div> {<br>
</div>
<div> System.out.println("am i print first
?");<br>
</div>
<div> }<br>
</div>
<div> }</div>
</div>
<br>
<br>
<blockquote style="border-left:2px solid
rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
<div>Thanks,</div>
<div>Gavin</div>
<br>
<br>
</blockquote>
<br>
<div>Rémi<br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</blockquote>
</div>
</div>
</blockquote>
<br><br></blockquote></div></div></body></html>