Skip to content

Support instance main methods and parameterless main methods #35785

Open
@wilkinsona

Description

@wilkinsona

Java 21 introduces (as a preview) support for instance main methods and for main methods (static or instance) that have no parameters:

Selecting a main method

When launching a class, the launch protocol chooses the first of the following methods to invoke:

  • A static void main(String[] args) method of non-private access (i.e., public, protected or package) declared in the launched class,
  • A static void main() method of non-private access declared in the launched class,
  • A void main(String[] args) instance method of non-private access declared in the launched class or inherited from a superclass, or, finally,
  • A void main() instance method of non-private access declared in the launched class or inherited from a superclass.

To support these new main methods, some changes will be required in Boot:

  • MainClassFinder, as used by our Maven and Gradle plugins (and Antlib), only looks for public static void main(String[] args) methods at the moment
  • MainMethodRunner, as used by our launchers, only supports running a static main(String[]) method at the moment
  • DevTools ( see MainMethod), only supports static main(String[]) methods when finding the method to use for restart at the moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions