[External] : Re: JEP draft: Implicit Classes and Enhanced Main Methods (Preview)

Ron Pressler ron.pressler at oracle.com
Wed Feb 15 23:52:24 UTC 2023



On 15 Feb 2023, at 18:18, Remi Forax <forax at univ-mlv.fr<mailto:forax at univ-mlv.fr>> wrote:

What is the behaviors of the compiler for

  var hello() { }
  var hello() { return; }
  var hello() { return null; }
  var foo;
  var foo = null;

  record hello() { }
  record hello() { return; }
  record hello() { return null; }
  record foo;
  record foo = null;

  record main() { }
  record main() { return; }
  static record main() { }
  static record main() { return; }
  record main;
  record main = null;



All of these except for `record hello() {}`, `record main() {}`, and `static record main() {}` are compile-time errors.

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.

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).

— Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20230215/06262b7a/attachment-0001.htm>


More information about the amber-spec-experts mailing list