RFR: JDK-8306112 Implementation of JEP 445: Unnamed Classes and Instance Main Methods (Preview) [v8]
Jaikiran Pai
jpai at openjdk.org
Fri May 5 09:33:22 UTC 2023
On Mon, 1 May 2023 13:06:24 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:
>> Add flexible main methods and anonymous main classes to the Java language.
>
> Jim Laskey has updated the pull request incrementally with two additional commits since the last revision:
>
> - Anonymous main classes renamed to unnamed classes
> - Add test
src/java.base/share/classes/jdk/internal/misc/MainMethodFinder.java line 139:
> 137: public static Method findMainMethod(Class<?> mainClass) throws NoSuchMethodException {
> 138: try {
> 139: Method mainMethod = mainClass.getMethod("main", String[].class);
Hello Jim, I think this specific line is trying to find a `public static void main(String[])` method from the launched class. In the current form of this implementation, this has the potential of returning a non-static `public void main(String[])` from here. I think a `isStatic(mainMethod)` would be needed here before returning this method as the found method.
src/java.base/share/classes/jdk/internal/misc/MainMethodFinder.java line 142:
> 140:
> 141: if (mainMethod.getDeclaringClass() != mainClass) {
> 142: System.err.println("WARNING: static main in super class will be deprecated.");
Similarly, this warning would have to be logged only if the method is `static`. Furthermore, do you think we should include the declaring class in the log message to provide some context on what's causing this warning? Something like:
> WARNING: static main(String[]) in super class foo.bar.Parent will be deprecated.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1185882851
PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1185885497
More information about the compiler-dev
mailing list