Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8319252

CSR JEP 463: JLS Changes for Implicitly Declared Classes and Instance Main Methods (Second Preview)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 22
    • specification
    • 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:

      1. flexible main methods allow the main entry point to a program to allow different signatures. In particular, they allow a main method to have no parameters, they allow a main method to have any non-private access, and they allow it to be an instance method. An instance main method can be invoked by the launcher if the launched class has a non-private no-args constructor.

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

          Activity

            People

              gbierman Gavin Bierman
              gbierman Gavin Bierman
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: