Java Reference
In-Depth Information
The newInstance method of Class invokes only a no-arg constructor. If
you want to invoke any other constructor then you must use the Class
object to get the relevant Constructor object and invoke newInstance on
that Constructor , passing the appropriate parameters.
The Constructor class, together with its inherited Member methods allows
you to obtain complete information about the declaration of a construct-
or and allows you to invoke the constructor to obtain a new instance of
that class.
public Type[] getGenericParameterTypes()
Returns an array of Type objects for each of the parameter
types accepted by this constructor, in the order in which the
parameters are declared. If the constructor has no paramet-
ers an empty array is returned.
public Type[] getGenericExceptionTypes()
Returns an array of Type objects for each of the exception
types listed in the throws clause for this constructor, in the or-
der they are declared. If there are no declared exceptions an
empty array is returned.
As with Method objects, the above are mirrored by the legacy versions
getParameterTypes and getExceptionTypes , respectively.
The Constructor class is similar to Method , implementing the same in-
terfaces ( AnnotatedElement and GenericDeclaration ) and defining similar
methods ( getParameterAnnotations and isVarArgs ).
To create a new instance of a class from a Constructor object, you invoke
its newInstance method.
public T newInstance(Object... args) throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTar-
getException
 
Search WWH ::




Custom Search