fix:修复编译后参数名称被编译器优化,无法获取到 main 方法的问题

This commit is contained in:
wangxiang
2024-07-05 10:07:17 +08:00
parent 2150e97131
commit baff3b6fe9

View File

@@ -890,12 +890,15 @@ public class JavaClass extends AccessFlags implements Cloneable, Node, Comparabl
* 获取 main 方法
*/
public JavaMethod getMainMethod() {
for (JavaMethod javaMethod : getMethods()) {
if (javaMethod.toString().startsWith("public static void main(String[] args)")) {
return javaMethod;
for (JavaMethod method : getMethods()) {
if (method.isPublic()
&& method.isStatic()
&& method.getName().equals("main")
&& method.getSignature().equals("([Ljava/lang/String;)V")) {
return method;
}
}
return null;
throw new RuntimeException("can not found main() method");
}
@SneakyThrows