O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Discovering Class Constructors

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required