Top Description Fields Constructors Methods
jdk.internal.misc

public Class MethodFinder

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, .Modifier, jdk.internal.access.JavaLangAccess, .SharedSecrets

A collection of static methods that return specific method objects of interest.

Field Summary

Modifier and TypeField and Description
private static final JavaLangAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Method

Returns:

the main method if a method found or null if no method is found
findMainMethod
(Class<?> cls)

Return the first method that meets the requirements of an application main method 12.1.4.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JLAback to summary
private static final JavaLangAccess JLA

Constructor Detail

MethodFinderback to summary
private MethodFinder()

Method Detail

findMainMethodback to summary
public static Method findMainMethod(Class<?> cls)

Return the first method that meets the requirements of an application main method 12.1.4. The method must:

  • be declared in this class's hierarchy
  • have the name "main"
  • have a single argument of type String[], String... or no argument
  • have the return type of void
  • be public, protected or package private
  • not be abstract
The method returned would be used by a launcher to initiate the execution of an application. Searching continues until a main method is found or the search is exhausted. The primary search occurs in two phases, once for a main method with a String[] or String... argument and failing that, once for a main method with a no arguments. The search itself uses recursion to first look at methods in this class, then default methods in this class's interface hierarchy and then repeating these steps with the class's super class.

API Note

The method returned may be declared in this class, a super class or as a default method of an interface that the class or super class implements.

It is not possible to declare a static main method and instance main method with the same signature in the same class. 8.4.2 states that "It is a compile-time error to declare two methods with override-equivalent signatures in a class."

SecurityExceptions can halt the search. In this case, a null is returned.

Returns:Method

the main method if a method found or null if no method is found

Java Language Specification
8.2 Class Members, 8.4 Method Declarations, 8.4.2 Method Signature, 12.1.4 Invoke a main method