On 15 Feb 2023, at 18:18, Remi Forax 
<[email protected]<mailto:[email protected]>> 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

Reply via email to