November 2006
Intermediate to advanced
224 pages
3h 29m
English
Class c = someObject.getClass(); Constructor[] constructors = c.getConstructors(); for (int i = 0; i < constructors.length; i++) { Class[] paramTypes = constructors[i].getParameterTypes(); for (int k = 0; k < paramTypes.length; k ++) { String paramTypeStr = paramTypes[k].getName(); System.out.print(paramTypeStr + " "); } System.out.println(); } |
You can get information about a class’s public constructors by calling the getConstructors() method on a Class object. This method returns an array of Constructor objects. Using the Constructor object, you can then get the constructor’s name, modifiers, parameter types, and throwable exceptions. The Constructor object also has a newInstance() method that allows you to create ...
Read now
Unlock full access