Class: getDeclaredConstructors()
/*
java.util.ArrayList:
java.util.ArrayList: Collection
java.util.ArrayList: int
*/
import java.lang.reflect.Constructor;
public class MainClass {
public static void main(String[] args) {
try {
Class c = Class.forName("java.util.ArrayList");
Constructor constructors[] = c.getDeclaredConstructors();
for (int i = 0; i < constructors.length; i++) {
System.out.print(constructors[i].getName() + ": ");
Class parameters[];
parameters = constructors[i].getParameterTypes();
for (int j = 0; j < parameters.length; j++) {
String s = parameters[j].getName();
s = s.substring(s.lastIndexOf(".") + 1, s.length());
System.out.print(s + " ");
}
System.out.println("");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Related examples in the same category