I'm writing a tester for myself that is meant to work with different classes whose names are given in the form of a string. Currently, my setup looks like this:
public class Tester {
public static void main(String[] args) throws /** some exceptions **/ {
Class<?> class = Class.forName("Ex");
Method main = class.getDeclaredMethod("main", String[].class);
main.invoke(null);
}
}
//yes, these are in separate files
public class Ex {
public static void main(String[] args) {
//...
}
}
At runtime, I'm thrown an exception with the following stack trace:
Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at Tester.main(Tester.java:56)