Details
-
CSR
-
Resolution: Approved
-
P4
-
None
-
minimal
Description
This is the CSR for the Java Language Specification changes of JEP 463 Implicitly Declared Classes and instance <code class="prettyprint" data-shared-secret="1726709461101-0.9356468918951639">main</code> methods (Second Preview)
Summary
Add flexible main
methods and implicitly declared main classes to the Java
language. This is a
preview language feature and API.
Problem
The Java language necessitates the explicit use of some programming-in-the-large constructs such as classes and access control even for the simplest of programs. This makes the language unnecessarily difficult to learn for programming beginners, and adds too much noise to small programs.
Solution
This change adds two features:
flexible
main
methods allow the main entry point to a program to allow different signatures. In particular, they allow amain
method to have no parameters, they allow amain
method to have any non-private access, and they allow it to be an instance method. An instancemain
method can be invoked by the launcher if the launched class has a non-private no-args constructor.A Java file that declares one or more methods outside a class declaration is defined to implicitly declare a top-level class. The name of this class is not specified, but in simple implementations of the Java SE Platform, where compilation units are stored in files, the name of this implicitly declared class would typically be the name of the file containing the simple compilation unit minus any extension (such as .java or .jav).
Specification
Details of the changes to the Java Language Specification & Java Virtual Machine Specification are attached and are also available at https://cr.openjdk.org/~gbierman/jep463/latest/.
Changes described above are only available with --enable-preview
. No class
file changes are required.
Attachments
Issue Links
- csr of
-
JDK-8318294 Implement JEP 463: JLS Changes for Implicitly Declared Classes and Instance Main Methods (Second Preview)
- Resolved
- relates to
-
JDK-8308111 JLS changes for Unnamed Classes and Instance main Methods (Preview)
- Resolved
-
JDK-8306113 Implementation for JEP 445: Unnamed Classes and Instance Main Methods (Preview)
- Closed