How to tell a method has a varargs argument using reflection?
- by Anthony Kong
Here is a sample code
package org.example;
import java.lang.reflect.Method;
class TestRef {
public void testA(String ... a) {
for (String i : a) {
System.out.println(i);
}
}
public static void main(String[] args){
Class testRefClass = TestRef.class;
for (Method m: testRefClass.getMethods()) {
if (m.getName() == "testA") {
System.out.println(m);
}
}
}
}
The output is
public void org.example.TestRef.testA(java.lang.String[])
So the signature of the method is reported to take a array of String.
Is there any mean in the reflection library I can tell that the method is originally declared to take a varargs?