<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>From: </b>"Archie Cobbs" <archie.cobbs@gmail.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"daniel smith" <daniel.smith@oracle.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Wednesday, December 13, 2023 5:29:27 PM<br><b>Subject: </b>Re: Field initialization before 'super'<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;"><div dir="ltr"><div dir="ltr">On Wed, Dec 13, 2023 at 10:02 AM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> No such restriction is needed for non-final fields; but it's an open question<br>
> whether we should prohibit all writes before 'this()' anyway.<br>
<br>
I would say, keep that restriction.<br></blockquote><br><div>I tend to agree. One benefit would be it creates more separation between final fields and non-final fields, which would help encourage people to make fields final so they get all the benefits.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Writes to non-final fields with initializers are disallowed, to avoid confusion<br>
> about sequencing (the field initializer will always run later, overwriting<br>
> whatever you put in the constructor prologue.)<br>
<br>
This seems to suggest that final fields with initializer should be written before the call to super() by default even if it's not a backward compatible change.<br></blockquote><br><div>That could only work if the initializer doesn't read "this"... which means only some initializers would qualify, which would be confusing.</div></div></div></blockquote><div><br></div><div>yes,<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;"><div dir="ltr"><div class="gmail_quote"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
captured fields in lambda are like strict but captured fields is inner classes are like normal fields.<br></blockquote><br><div>I was curious why this would be true and it appears it's not true, at least from this test:</div><br><div style="margin-left:40px"><span style="font-family:monospace">$ cat Test.java<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">public class Test {<br> public Test(String x) {<br> new Runnable() {<br> @Override<br> public void run() {<br> System.out.println(x);<br> }<br> }.run();<br> }<br>} <br></span></div><div style="margin-left:40px"><span style="font-family:monospace">$ javap -c -classpath classes Test\$1<br>Compiled from "Test.java"<br>class Test$1 implements java.lang.Runnable {<br> final java.lang.String val$x;<br><br> Test$1();<br> Code:<br> 0: aload_0<br> 1: aload_2<br> 2: putfield #1 // Field val$x:Ljava/lang/String;<br> 5: aload_0<br> 6: invokespecial #7 // Method java/lang/Object."<init>":()V<br> 9: return<br>...<br></span></div><br><div>You can see in the Test$1 constructor Test$1.x is being initialized prior to super().</div></div></div></blockquote><div><br></div><div>Yes, but you can still change the value of the field by reflection, unlike with the fields of a lambda proxy, so the field containing the captured value is not strict.<br></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;"><div dir="ltr"><div class="gmail_quote"><div><br></div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> - Can I have my implicit 'super()' call go at the end of my constructor?<br></blockquote><br><div>My opinion is also "no" on this question... but because it would add another logical fork in developers' minds for too little benefit. It's easy enough to just put it in there explicitly.</div></div></div></blockquote><div><br></div><div>What we are trying to do here, is to follow Dan's idea that there is no need for an additional keyword and that the compiler can infer the strictness by itself.<br data-mce-bogus="1"></div><div>As you said, the problem of that idea is that the developer is not really in control, subtle changes like the initializer depending on 'this' make the final field strict or not.<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;"><div dir="ltr"><div class="gmail_quote"><div><br></div><br><div>-Archie</div></div></div></blockquote><div><br></div><div>regards,<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;"><div dir="ltr"><div class="gmail_quote"><div><br></div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs</div></div><br></blockquote></div></div></body></html>