Main Page | Class Hierarchy | Class List | Directories | Class Members | Related Pages

java.lang.reflect.Constructor Class Reference

Inheritance diagram for java.lang.reflect.Constructor:

java.lang.reflect.AccessibleObject List of all members.

Detailed Description

This class must be implemented by the vm vendor.

This class models a constructor. Information about the constructor can be accessed, and the constructor can be invoked dynamically.


Public Member Functions

boolean equals (Object object)
 Compares the specified object to this Constructor and answer if they are equal.
Class getDeclaringClass ()
 Return the java.lang.Class associated with the class that defined this constructor.
Class[] getExceptionTypes ()
 Return an array of the java.lang.Class objects associated with the exceptions declared to be thrown by this constructor.
int getModifiers ()
 Return the modifiers for the modelled constructor.
String getName ()
 Return the name of the modelled constructor.
Class[] getParameterTypes ()
 Return an array of the java.lang.Class objects associated with the parameter types of this constructor.
int hashCode ()
 Answers an integer hash code for the receiver.
Object newInstance (Object args[]) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
 Return a new instance of the declaring class, initialized by dynamically invoking the modelled constructor.
String toString ()
 Answers a string containing a concise, human-readable description of the receiver.


Member Function Documentation

boolean java.lang.reflect.Constructor.equals Object  object  ) 
 

Compares the specified object to this Constructor and answer if they are equal.

The object must be an instance of Constructor with the same defining class and parameter types.

Parameters:
object the object to compare
Returns:
true if the specified object is equal to this Constructor, false otherwise
See also:
hashCode

Class java.lang.reflect.Constructor.getDeclaringClass  ) 
 

Return the java.lang.Class associated with the class that defined this constructor.

Returns:
the declaring class

Class [] java.lang.reflect.Constructor.getExceptionTypes  ) 
 

Return an array of the java.lang.Class objects associated with the exceptions declared to be thrown by this constructor.

If the constructor was not declared to throw any exceptions, the array returned will be empty.

Returns:
the declared exception classes

int java.lang.reflect.Constructor.getModifiers  ) 
 

Return the modifiers for the modelled constructor.

The Modifier class should be used to decode the result.

Returns:
the modifiers
See also:
java.lang.reflect.Modifier

Reimplemented from java.lang.reflect.AccessibleObject.

String java.lang.reflect.Constructor.getName  ) 
 

Return the name of the modelled constructor.

This is the name of the declaring class.

Returns:
the name

Class [] java.lang.reflect.Constructor.getParameterTypes  ) 
 

Return an array of the java.lang.Class objects associated with the parameter types of this constructor.

If the constructor was declared with no parameters, the array returned will be empty.

Returns:
the parameter types

int java.lang.reflect.Constructor.hashCode  ) 
 

Answers an integer hash code for the receiver.

Objects which are equal answer the same value for this method. The hash code for a Constructor is the hash code of the declaring class' name.

Returns:
the receiver's hash
See also:
equals

Object java.lang.reflect.Constructor.newInstance Object  args[]  )  throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
 

Return a new instance of the declaring class, initialized by dynamically invoking the modelled constructor.

This reproduces the effect of new declaringClass(arg1, arg2, ... , argN) This method performs the following:

  • A new instance of the declaring class is created. If the declaring class cannot be instantiated (i.e. abstract class, an interface, an array type, or a base type) then an InstantiationException is thrown.
  • If this Constructor object is enforcing access control (see AccessibleObject) and the modelled constructor is not accessible from the current context, an IllegalAccessException is thrown.
  • If the number of arguments passed and the number of parameters do not match, an IllegalArgumentException is thrown.
  • For each argument passed:
    • If the corresponding parameter type is a base type, the argument is unwrapped. If the unwrapping fails, an IllegalArgumentException is thrown.
    • If the resulting argument cannot be converted to the parameter type via a widening conversion, an IllegalArgumentException is thrown.
  • The modelled constructor is then invoked. If an exception is thrown during the invocation, it is caught and wrapped in an InvocationTargetException. This exception is then thrown. If the invocation completes normally, the newly initialized object is returned.

Parameters:
args the arguments to the constructor
Returns:
the new, initialized, object
Exceptions:
java.lang.InstantiationException if the class cannot be instantiated
java.lang.IllegalAccessException if the modelled constructor is not accessible
java.lang.IllegalArgumentException if an incorrect number of arguments are passed, or an argument could not be converted by a widening conversion
java.lang.reflect.InvocationTargetException if an exception was thrown by the invoked constructor
See also:
java.lang.reflect.AccessibleObject

String java.lang.reflect.Constructor.toString  ) 
 

Answers a string containing a concise, human-readable description of the receiver.

The format of the string is modifiers (if any) declaring class name '(' parameter types, separated by ',' ')' If the constructor throws exceptions, ' throws ' exception types, separated by ',' For example: public String(byte[],String) throws UnsupportedEncodingException

Returns:
a printable representation for the receiver


The documentation for this class was generated from the following file:
(c) Copyright 2005 The Apache Software Foundation or its licensors, as applicable.