On Mon, 1 May 2023 13:06:24 GMT, Jim Laskey <jlas...@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 152: > 150: > 151: List<Method> mains = new ArrayList<>(); > 152: gatherMains(mainClass, mainClass, mains); The `try` block above is there to find `public static void main(String[])` in the launched class. When it's not found, then we gather the potential main methods (as listed in the JEP). The implementation of `gatherMains(...)`, in its current form starts gathering the main methods from `refc.getSuperclass()`, where `refc` in this case is the `mainClass`, which is the launched class. So if I'm reading this correctly, then I think it's going to completely skip the launched class for looking any potential main methods and instead start looking for them in the launched class' super hierarchy. src/java.base/share/classes/jdk/internal/misc/MainMethodFinder.java line 158: > 156: } > 157: > 158: mains.sort(MainMethodFinder::compareMethods); Perhaps skip the call to `sort` and just return the found main method if `mains.size() == 1`? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1185890136 PR Review Comment: https://git.openjdk.org/jdk/pull/13689#discussion_r1185892782