You will need to use
m.invoke(null, (Object)new String[] {});
The invoke(Object, Object...) method accepts Object... (Correction) The String[] array that is used is used as Object[] and is empty, so it has no elements to jump to the method call. Dropping it on an Object , you say that this is the only element in the wrapper of Object[] .
This is due to covariance of the array. You can do
public static void method(Object[] a) {} ... method(new String[] {});
Since a String[] is an Object[] .
System.out.println(new String[]{} instanceof Object[]);
Alternatively, you can wrap String[] in Object[]
m.invoke(null, new Object[]{new String[] {}});
The method will then use the elements in Object[] as arguments to invoke the method.
Cautiously using a StackOverflowError call to main(..) .
source share