<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>"Ron Pressler" <ron.pressler@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"amber-spec-experts" <amber-spec-experts@openjdk.org><br><b>Sent: </b>Thursday, February 16, 2023 12:52:24 AM<br><b>Subject: </b>Re: [External] : Re: JEP draft: Implicit Classes and Enhanced Main Methods (Preview)<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;">
<br class="">
<div><br class="">
<blockquote class="">
<div class="">On 15 Feb 2023, at 18:18, Remi Forax <<a href="mailto:forax@univ-mlv.fr" class="" target="_blank">forax@univ-mlv.fr</a>> wrote:</div>
<div class="">
<div class="">
<div style="font-family: arial, helvetica, sans-serif; font-size: 12pt;" class="">
<div class=""><br class="">
</div>
<div class="">
<div class="">What is the behaviors of the compiler for<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">  var hello() { }</div>
<div class="">  var hello() { return; }</div>
<div class="">  var hello() { return null; }</div>
<div class="">  var foo;<br class="">
</div>
  var foo = null;</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">  record hello() { }</div>
<div class="">  record hello() { return; }</div>
<div class="">  record hello() { return null; }</div>
<div class="">  record foo;<br class="">
</div>
<div class="">  record foo = null;</div>
<div class=""><br class="">
</div>
<div class="">  record main() { }<br class="">
</div>
<div class="">  record main() { return; }<br class="">
</div>
<div class="">  static record main() { }<br class="">
</div>
<div class="">  static record main() { return; }<br class="">
</div>
<div class="">  record main;<br class="">
</div>
<div class="">  record main = null;<br class="">
</div>
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br class="">
<div class=""><br class="">
</div>
<div class="">All of these except for `record hello() {}`, `record main() {}`, and `static record main() {}` are compile-time errors.</div>
<div class=""><br class="">
</div>
<div class="">An implicit class is compiled as if the entire content of the file (except import statements) are enclosed in a final class declaration with some unknown name. Because there is no name, you can’t declare a constructor (or use a method reference
 to a static method). The meaning of all members is interpreted in the usual way.</div></blockquote><div><br></div><div>or refers to "this" by the name of the class.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>My questions was more about the error messages students will get when writing one of these lines.<br data-mce-bogus="1"></div><div>Usually students struggle not because they have make a mistake but because they are not able to understand how to fix it.</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 class=""><br class="">
</div>
<div class="">The only special rules are that an implicit class must be in the unnamed package and it must contain a main entry point (if it didn’t have an entry point there would be no way of using the class — you can’t invoke a static method on it from some
 other class or instantiate it because it’s unnamed).</div></blockquote><div><br></div><div>I still think that fields should not be allowed inside an implicit class, because when you remove the class declaration a field and a local variable are too similar and because an implicit class has no user defined constructor.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Here is a series of examples showing how confusing it can be.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>   Object var, record; <br></div><div>   void main() {<br data-mce-bogus="1"></div><div>     System.out.println(var);  // compiles<br data-mce-bogus="1"></div><div>   }</div><div>  <div>   void main() {</div><div>     Object var, record; <br data-mce-bogus="1"></div><div>     System.out.println(var);   // does not compile<br></div><div>   }</div><div>  <div>   Object var, record; <br></div><div>   static void main() {</div><div>     System.out.println(var);   // does not compile<br></div><div>   }</div><br data-mce-bogus="1"></div><div>   static Object var, record; <br></div><div>   void main() {</div><div>     System.out.println(var);   // compiles but awful<br></div><div>   }</div><div><br data-mce-bogus="1"></div><div>  void main() {<br data-mce-bogus="1"></div><div>   var var = 3;<br data-mce-bogus="1"></div><div>   System.out.println(var);  // compiles<br data-mce-bogus="1"></div><div>  }<br data-mce-bogus="1"></div><div>  <br data-mce-bogus="1"></div><div> var var = 3;  // does not compile<br data-mce-bogus="1"></div><div> <div> void main() {  <br></div><div>   System.out.println(var);<br></div><div>  }</div><br data-mce-bogus="1"></div></div><div><br data-mce-bogus="1"></div><div>Also conceptually, being able to define fields without constructors is problematic, because you are bypassing the the notion of encapsulation.<br data-mce-bogus="1"></div><div>Implicit class instance fields are more complex that usual class fields because of the lack of constructors.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Teaching using a simpler model is great but not if as a student you have to unlearn something previously introduced.</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 class=""><br class="">
</div>
<div class="">— Ron</div></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>