ConstructorT


Constructor<T> java.lang.reflect

Java 1.1

This class represents a constructor method of a class. Instances of Constructor are obtained by calling getConstructor( ) and related methods of java.lang.Class . Constructor implements the Member interface, so you can use the methods of that interface to obtain the constructor name , modifiers, and declaring class. In addition, getParameterTypes( ) and getExceptionTypes( ) also return important information about the represented constructor.

In addition to these methods that return information about the constructor, the newInstance( ) method allows the constructor to be invoked with an array of arguments in order to create a new instance of the class that declares the constructor. If any of the arguments to the constructor are of primitive types, they must be converted to their corresponding wrapper object types to be passed to newInstance( ) . If the constructor causes an exception, the THRowable object it throws is wrapped within the InvocationTargetException that is thrown by newInstance( ) . Note that newInstance( ) is much more useful than the newInstance( ) method of java.lang.Class because it can pass arguments to the constructor.

Constructor has been modified in Java 5.0 to support generics, annotations, and varargs . The changes are the same as the Java 5.0 changes to the Method class. Additionally, Constructor has been made a generic type in Java 5.0. The type variable T represents the type that the constructor constructs, and is used as the return type of the newInstance( ) method.

Figure 10-92. java.lang.reflect.Constructor<T>

 public final class  Constructor<T>  extends AccessibleObject implements  GenericDeclaration, Member {  // No Constructor   // Public Instance Methods  public Class<?>[ ]  getExceptionTypes  ( );  5.0  public Type[ ]  getGenericExceptionTypes  ( );  5.0  public Type[ ]  getGenericParameterTypes  ( );  5.0  public java.lang.annotation.Annotation[ ][ ]  getParameterAnnotations  ( );        public Class<?>[ ]  getParameterTypes  ( );  5.0  public boolean  isVarArgs  ( );        public T  newInstance  (Object ...  initargs  )  throws InstantiationException, IllegalAccessException, IllegalArgumentException,  InvocationTargetException;  5.0  public String  toGenericString  ( );  // Methods Implementing GenericDeclaration   5.0  public TypeVariable<Constructor<T>>[ ]  getTypeParameters  ( );  // Methods Implementing Member  public Class<T>  getDeclaringClass  ( );        public int  getModifiers  ( );        public String  getName  ( );  5.0  public boolean  isSynthetic  ( );  // Public Methods Overriding AccessibleObject   5.0  public <T extends java.lang.annotation.Annotation> T  getAnnotation  (Class<T>  annotationClass  );  5.0  public java.lang.annotation.Annotation[ ]  getDeclaredAnnotations  ( );  // Public Methods Overriding Object  public boolean  equals  (Object  obj  );        public int  hashCode  ( );        public String  toString  ( );   } 

Returned By

Class.{getConstructor( ) , getConstructors( ) , getdeclaredConstructor( ) , geTDeclaredConstructors( ) , getEnclosingConstructor( )}



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net