| findMainMethod | back 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
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
|
| isValidMainMethod | back to summary
|
|---|
| private static boolean isValidMainMethod(Class<?> initialClass, Method mainMethodCandidate)
|