I have the following two pieces of code:
public class C {
public void method1(String[] args) {
}
public void method2(String... args) {
}
}
Then I obtain Method instances of the methods above using reflection.
Method m1 = nil;
Method m2 = nil;
Class c = Class.forName("C");
for (Method m : c.getMethods()) {
if (m.getName().equals("method1")) m1 = m;
if (m.getName().equals("method2")) m2 = m;
}
m1.getParameters() and m2.getParameters() return equals lists of Class instances.
argument of m1 and argument of m2 are both represented as arrays. But actually they are not same. Compiler will not allow
m1("a", "b");
The question is:
Is there any flag that specify whether parameter is variadic or just regular array?
Class java.lang.reflect.Method has method isVarArg(). It shows whether the last argument of the method is variadic.