Java Constructor .getParameterTypes ()
Syntax
Constructor.getParameterTypes() has the following syntax.
public Class <?>[] getParameterTypes()
Example
In the following code shows how to use Constructor.getParameterTypes() method.
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
//from ww w . jav a 2 s . c om
public class Main {
public static void main(String[] argv) throws Exception {
Constructor[] constructors = String.class.getDeclaredConstructors();
for (int i = 0; i < constructors.length; i++) {
Constructor c = constructors[i];
Class[] paramTypes = c.getParameterTypes();
String name = c.getName();
System.out.print(Modifier.toString(c.getModifiers()));
System.out.print(" " + name + "(");
for (int j = 0; j < paramTypes.length; j++) {
if (j > 0)
System.out.print(", ");
System.out.print(paramTypes[j].getCanonicalName());
}
System.out.println(");");
}
}
}
The output: