Reputation: 978
I am using reflection to create dynamic examples for my functions written under one class.
i.e below are my functions :
public void doSomething(int... args)
{
...
}
// Example to generate : doSomething(1,2,3,4,5);
public void doSomething2(int[] argsAsArray)
{
...
}
// Example to generate : doSomething2(new int[]{1,2,3,4,5})
My problem is, I am not able to differentiate between the types of Variable args v/s Array type of argument.
Is there a way that using which I can determine whether parameter type is Variable args or an Array ?
Upvotes: 0
Views: 190
Reputation: 1764
for (Method m : YourClass.class.getDeclaredMethods()) {
System.out.println(m.getName() + " varargs? " + m.isVarArgs());
}
Upvotes: 2