|
Generated by JDiff |
||||||||
PREV PACKAGE NEXT PACKAGE FRAMES NO FRAMES |
This file contains all the changes in documentation in the packagejava.lang.reflect
as colored differences. Deletions are shownlike this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.
Get the value of the accessible flag for this object. @return the value of the object's accessible flag
Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:Class Array, Object newInstance(Class, int[])@param componentType theint[] x = {length}; Array.newInstance(componentType x);Class
object representing the component type of the new array @param length the length of the new array @return the new array @exception NullPointerException if the specifiedcomponentType
parameter is null @exception IllegalArgumentException if componentType is Void.TYPE @exception NegativeArraySizeException if the specifiedlength
is negative
Creates a new array with the specified component type and dimensions. IfClass Array, void setBoolean(Object, int, boolean)componentType
represents a non-array class or interface the new array hasdimensions.length
dimensions andcomponentType
as its component type. IfcomponentType
represents an array class the number of dimensions of the new array is equal to the sum ofdimensions.length
and the number of dimensions ofcomponentType
. In this case the component type of the new array is the component type ofcomponentType
.The number of dimensions of the new array must not exceed the number of array dimensions supported by the implementation (typically 255). @param componentType the
Class
object representing the component type of the new array @param dimensions an array ofint
types representing the dimensions of the new array @return the new array @exception NullPointerException if the specifiedcomponentType
argument is null @exception IllegalArgumentException if the specifieddimensions
argument is a zero-dimensional array or if the number of requested dimensions exceeds the limit on the number of array dimensions supported by the implementation (typically 255) or if componentType is Void.TYPE. @exception NegativeArraySizeException if any of the components in the specifieddimensions
argument is negative.
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setByte(Object, int, byte)boolean
value. @param array the array @param index the index into the array @paramvaluez the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setChar(Object, int, char)value. @param array the array @param index the index into the array @param
booleanbytevalueb the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setDouble(Object, int, double)value. @param array the array @param index the index into the array @param
bytecharvaluec the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setFloat(Object, int, float)double
value. @param array the array @param index the index into the array @paramvalued the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setInt(Object, int, int)float
value. @param array the array @param index the index into the array @paramvaluef the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setLong(Object, int, long)int
value. @param array the array @param index the index into the array @paramvaluei the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedClass Array, void setShort(Object, int, short)long
value. @param array the array @param index the index into the array @paramvaluel the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Sets the value of the indexed component of the specified array object to the specifiedshort
value. @param array the array @param index the index into the array @paramvalues the new value of the indexed component @exception NullPointerException If the specified object argument is null @exception IllegalArgumentException If the specified object argument is not an array or if the the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening widening conversion @exception ArrayIndexOutOfBoundsException If the specifiedindex
argument is negative or if it is greater than or equal to the length of the specified array @see Array#set
Class Constructor, Class[] getExceptionTypes()Constructor
provides information about and access to a single constructor for a class.
Constructor
permits widening conversions to occur when matching the actual parameters to newInstance() with the underlying constructor's formal parameters but throws anIllegalArgumentException
if a narrowing conversion would occur. @see Member @see java.lang.Class @see java.lang.Class#getConstructors() @see java.lang.Class#getConstructor(Class[]) @see java.lang.Class#getDeclaredConstructors() @author Kenneth Russell @author Nakul Saraiya
Returns an array ofClass Constructor, Class[] getParameterTypes()Class
objects that represent the types of of exceptions declared to be thrown by the underlying constructor represented by thisConstructor
object. Returns an array of length 0 if the constructor declares no exceptions in itsthrows
clause. @return the exception types declared as being thrown by the constructor this object represents
Returns an array ofClass Constructor, Object newInstance(Object[])Class
objects that represent the formal parameter types in declaration order of the constructor represented by thisConstructor
object. Returns an array of length 0 if the underlying constructor takes no parameters. @return the parameter types for the constructor this object represents
Uses the constructor represented by thisConstructor
object to create and initialize a new instance of the constructor's declaring class with the specified initialization parameters. Individual parameters are automatically unwrapped to match primitive formal parameters and both primitive and reference parameters are subject to method invocation conversions as necessary.Returns the newly created and initialized object. Creation proceeds with the following steps in order: If the class that declares the underlying constructor represents an abstract class the creation throws an InstantiationException. If this Constructor object enforces Java language access control and the underlying constructor is inaccessible the creation throws an IllegalAccessException.If the number of
actual parameters supplied via initargs is different from the number offormal parameters required by the underlying constructorthe creation throws an IllegalArgumentException. A new instance of the constructor's declaring classiscreated and its fields are initialized to their default initial values. For each actual parameter in0 the suppliedinitargs
array: If the corresponding formal parameter has a primitive type an unwrapping conversion is attempted to convert the objectvalue to amayvaluebe ofthe primitive type. If this attempt fails thelengthcreation0throws anorIllegalArgumentExceptionnull.If
after possible unwrapping the parameter value cannot be converted tothecorresponding formal parameterrequiredtype by a method invocation conversionaccess and argument checks succeed and thecreation throws aninstantiationIllegalArgumentException.willTheproceed the constructor's declaring class is initialized if it has not already been initialized.A new instance ofIf the constructor
'sdeclaring classcompletes normallyisreturns the newly created anditsinitializedfieldsinstance.are@paraminitialized to their default initialinitargs array of objects tovalues.beControlpassed astransfersarguments to theunderlyingconstructortocall;initialize the newvalues of primitiveinstance.typesIf the constructor completes abruptly by throwing an exception theare wrapped in a wrapper object of the appropriate typeexception(e.g.isaplacedfloat inanaInvocationTargetExceptionFloatand@returnthrown in turn to the caller ofa new object created by calling thenewInstance.constructorIfthisthe constructorobject representscompletes@exceptionnormally returns theIllegalAccessException if thisnewlyConstructor
created and initializedobject enforces Javainstance.language@exceptionaccessIllegalAccessException ifcontrol and the underlying constructor is inaccessible. @exception IllegalArgumentException if the number of actual and formal parameters differor; if an unwrapping conversion for primitive arguments fails; or if after possible unwrapping a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversionfails. @exception InstantiationException if the class that declares the underlying constructor represents an abstract class. @exception InvocationTargetException if the underlying constructor throws an exception. @exception ExceptionInInitializerError if the initialization provoked by this method fails.
AClass Field, Object get(Object)Field
provides information about and dynamic access to a single field of a class or an interface. The reflected field may be a class (static) field or an instance field.A
Field
permits widening conversions to occur during a get or set access operation but throws anIllegalArgumentException
if a narrowing conversion would occur. @see Member @see java.lang.Class @see java.lang.Class#getFields() @see java.lang.Class#getField(String) @see java.lang.Class#getDeclaredFields() @see java.lang.Class#getDeclaredField(String) @author Kenneth Russell @author Nakul Saraiya
Returns the value of the field represented by thisClass Field, boolean getBoolean(Object)Field
on the specified object. The value is automatically wrapped in an object if it has a primitive type.The underlying field's value is obtained as follows:
If the underlying field is a static field the
obj
argument is ignored; it may be null.Otherwise the underlying field is an instance field. If the specified
obj
argument is null the method throws aNullPointerException.
If the specified object is not an instance of the class or interface declaring the underlying field the method throws anIllegalArgumentException
.If this
Field
object enforces Java language access control and the underlying field is inaccessible the method throws anIllegalAccessException
. If the underlying field is static the class that declared the field is initialized if it has not already been initialized.Otherwise the value is retrieved from the underlying instance or static field. If the field has a primitive type the value is wrapped in an object before being returned otherwise it is returned as is.
If the field is hidden in the type of
obj
the field's value is obtained according to the preceding rules. @param obj object from which the represented field's value is to be extracted @return the value of the represented field in object obj; primitive values are wrapped in an appropriate object before being returned @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof). @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails.
Gets the value of aClass Field, byte getByte(Object)field as astatic or instanceboolean
on the specified objectfield.This@parammethod is equivalentobj the object to((Boolean)get(obj)).booleanValue() exceptextractthat anthe
IllegalArgumentExceptionbooleanisvaluethrownfromif@return thefieldvaluecannot be converted toof thetypeboolean
by a widening conversion.field @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typeboolean
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of aClass Field, char getChar(Object)field as astatic or instancebyte
on the specified objectfield.This@parammethod is equivalentobj the object to((Number)get(obj)).byteValue() exceptextractthat anthe
IllegalArgumentExceptionbyteisvaluethrownfromif@return thefieldvaluecannot be converted toof thetypebyte
by a widening conversion.field @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typebyte
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, double getDouble(Object)as aof typechar
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Character)get(obj)).charValue()charexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptioncharisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypechar
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typechar
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, float getFloat(Object)as aof typedouble
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Number)get(obj)).doubleValue()doubleexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptiondoubleisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypedouble
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typedouble
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, int getInt(Object)as aof typefloat
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Number)get(obj)).floatValue()floatexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptionfloatisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypefloat
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typefloat
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, long getLong(Object)as anof typeint
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Number)get(obj)).intValue()intexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptionintisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypeint
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typeint
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, short getShort(Object)as aof typelong
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Number)get(obj)).longValue()longexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptionlongisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypelong
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typelong
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Gets the value of a static or instance fieldClass Field, Class getType()as aof typeshort
on the specifiedorobject.ofThis method is equivalentanother primitive type convertible to type
((Number)get(obj)).shortValue()shortexcept thatvia aanwidening conversion. @param obj the object to extract the
IllegalArgumentExceptionshortisvaluethrownfromif@return thefieldvaluecannot beof the field converted tothetypeshort
by a widening conversion.@exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if the field value cannot be converted to the typeshort
by a widening conversion. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#get
Returns aClass Field, void set(Object, Object)Class
object that identifies the declared type for the field represented by thisField
object. @return aClass
object identifying the declared type of the field represented by this object
Sets the field represented by thisClass Field, void setBoolean(Object, boolean)Field
object on the specified object argument to the specified new value. The new value is automatically unwrapped if the underlying field has a primitive type.The operation proceeds as follows:
If the underlying field is static the
obj
argument is ignored; it may be null.Otherwise the underlying field is an instance field. If the specified object argument is null the method throws a
NullPointerException
. If the specified object argument is not an instance of the class or interface declaring the underlying field the method throws anIllegalArgumentException
.If this
Field
object enforces Java language access control and the underlying field is inaccessible the method throws anIllegalAccessException
.If the underlying field is final the method throws an
IllegalAccessException
.If the underlying field is of a primitive type an unwrapping conversion is attempted to convert the new value to a value of a primitive type. If this attempt fails the method throws an
IllegalArgumentException
.If after possible unwrapping the new value cannot be converted to the type of the underlying field by an identity or widening conversion the method throws an
IllegalArgumentException
.If the underlying field is static the class that declared the field is initialized if it has not already been initialized.
The field is set to the possibly unwrapped and widened new value.
If the field is hidden in the type of
obj
the field's value is set according to the preceding rules. @param obj the object whose field should be modified @param value the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails.
Sets the value of a field as aClass Field, void setByte(Object, byte)boolean
on the specified object. This method is equivalent toset(obj zObj)
wherezObj
is aBoolean
object andzObj.booleanValue() == z
. @param obj the object whose field should be modified @param z the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as aClass Field, void setChar(Object, char)byte
on the specified object. This method is equivalent toset(obj bObj)
wherebObj
is aByte
object andbObj.byteValue() == b
. @param obj the object whose field should be modified @param b the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as aClass Field, void setDouble(Object, double)char
on the specified object. This method is equivalent toset(obj cObj)
wherecObj
is aCharacter
object andcObj.charValue() == c
. @param obj the object whose field should be modified @param c the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as aClass Field, void setFloat(Object, float)double
on the specified object. This method is equivalent toset(obj dObj)
wheredObj
is aDouble
object anddObj.doubleValue() == d
. @param obj the object whose field should be modified @param d the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as aClass Field, void setInt(Object, int)float
on the specified object. This method is equivalent toset(obj fObj)
wherefObj
is aFloat
object andfObj.floatValue() == f
. @param obj the object whose field should be modified @param f the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as anClass Field, void setLong(Object, long)int
on the specified object. This method is equivalent toset(obj iObj)
whereiObj
is aInteger
object andiObj.intValue() == i
. @param obj the object whose field should be modified @param i the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as aClass Field, void setShort(Object, short)long
on the specified object. This method is equivalent toset(obj lObj)
wherelObj
is aLong
object andlObj.longValue() == l
. @param obj the object whose field should be modified @param l the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
Sets the value of a field as ashort
on the specified object. This method is equivalent toset(obj sObj)
wheresObj
is aShort
object andsObj.shortValue() == s
. @param obj the object whose field should be modified @param s the new value for the field ofobj
being modified @exception IllegalAccessException if the underlyingconstructorfield is inaccessible. @exception IllegalArgumentException if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof) or if an unwrapping conversion fails. @exception NullPointerException if the specified object is null and the field is an instance field. @exception ExceptionInInitializerError if the initialization provoked by this method fails. @see Field#set
InvocationHandler
is the interface implemented by the invocation handler of a proxy instance.Each proxy instance has an associated invocation handler. When a method is invoked on a proxy instance the method invocation is encoded and dispatched to the
invoke
method of its invocation handler. @author Peter Jones @version 1.5 006 01/0212/0203 @see Proxy @since JDK1.3
InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.Class InvocationTargetException, constructor InvocationTargetException(Throwable)As of release 1.4 this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "target exception" that is provided at construction time and accessed via the #getTargetException() method is now known as the cause and may be accessed via the Throwable#getCause() method as well as the aforementioned "legacy method." @see Method @see Constructor
Constructs a InvocationTargetException with a target exception. @param target the target exceptionClass InvocationTargetException, constructor InvocationTargetException(Throwable, String)
Constructs a InvocationTargetException with a target exception and a detail message. @param target the target exception @param s the detail messageClass InvocationTargetException, Throwable getTargetException()
Get the thrown target exception.This method predates the general-purpose exception chaining facility. The Throwable#getCause() method is now the preferred means of obtaining this information. @return the thrown target exception (cause of this exception).
Returns the Class object representing the class or interface that declares the member or constructor represented by this Member. @return an object representing the declaring class of the underlying memberClass Member, int getModifiers()
Returns the Java language modifiers for the member or constructor represented by this Member as an integer. The Modifier class should be used to decode the modifiers in the integer. @return the Java language modifiers for the underlying member @see ModifierClass Member, String getName()
Returns the simple name of the underlying member or constructor represented by this Member. @return the simple name of the underlying member
AClass Method, Class[] getExceptionTypes()Method
provides information about and access to a single method on a class or interface. The reflected method may be a class method or an instance method (including an abstract method).A
Method
permits widening conversions to occur when matching the actual parameters to invokewith the underlying method's formal parameters but it throws anIllegalArgumentException
if a narrowing conversion would occur. @see Member @see java.lang.Class @see java.lang.Class#getMethods() @see java.lang.Class#getMethod(String Class[]) @see java.lang.Class#getDeclaredMethods() @see java.lang.Class#getDeclaredMethod(String Class[]) @author Kenneth Russell @author Nakul Saraiya
Returns an array ofClass Method, Class[] getParameterTypes()Class
objects that represent the types of the exceptions declared to be thrown by the underlying method represented by thisMethod
object. Returns an array of length 0 if the method declares no exceptions in itsthrows
clause. @return the exception types declared as being thrown by the method this object represents
Returns an array ofClass Method, Class getReturnType()Class
objects that represent the formal parameter types in declaration order of the method represented by thisMethod
object. Returns an array of length 0 if the underlying method takes no parameters. @return the parameter types for the method this object represents
Returns aClass Method, Object invoke(Object, Object[])Class
object that represents the formal return type of the method represented by thisMethod
object. @return the return type for the method this object represents
Invokes the underlying method represented by thisMethod
object on the specified object with the specified parameters. Individual parameters are automatically unwrapped to match primitive formal parameters and both primitive and reference parameters are subject towideningmethod invocation conversions as necessary.The value returned by the underlying method is automatically wrapped in an object if it has a primitive type.
Method invocation proceeds with the following steps in order:If the underlying method is static then the specifiedobj
argument is ignored. It may be null.
Otherwise the method is an instance method. If the specified object argument is null the invocation throws a NullPointerException. Otherwise if the specified object argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof) the invocation throws an IllegalArgumentException.Ifthis Method object enforces Java language access control and the underlying method is inaccessible the invocation throws an IllegalAccessException. If the number of actual parameters supplied via args is different fromthe number of formal parameters required by the underlying methodthe invocation throws an IllegalArgumentException. For each actual parameterisin0 the suppliedargs
array: If the corresponding formal parameter has a primitive type an unwrapping conversion is attempted to convert the object value to a value of a primitive type. If this attempt fails the invocation throws an IllegalArgumentException. If after possible unwrapping the parameter valuecannotmay beconverted to the corresponding formal parameter type by a method invocation conversion theofinvocation throws anlength 0 orIllegalArgumentExceptionnull.If the underlying method is an instance method it is invoked using dynamic method lookup as documented in The Java Language Specification Second Edition section 15.
1112.4.4; in particular overriding based on the runtime type of the target object will occur.If the underlying method is static the class that declared the method is initialized if it has not already been initialized.
The underlying method is invoked directly. Control transfers to the invoked method. If the method completes abruptly by throwing an exception the exception is placed in an InvocationTargetException and thrown in turn to the caller of invoke.If the method completes normally the value it returns is returned to the caller of invoke; if the value has a primitive type it is first appropriately wrapped in an object. If the underlying method return type is void the invocation returns null. @param obj the object the underlying method is invoked from @param args the arguments used for the method call @return the result of dispatching the method represented by this object on
obj
with parametersargs
@exception IllegalAccessException if thisMethod
object enforces Java language access control and the underlying method is inaccessible. @exception IllegalArgumentException if the method is an instance method and the specified object argument is not an instance of the class or interface declaring the underlying method (or of a subclass or implementor thereof); if the number of actual and formal parameters differor; if an unwrapping conversion for primitive arguments fails; or if after possible unwrapping a parameter value cannot be converted to the corresponding formal parameter type by a method invocation conversion. @exception InvocationTargetException if the underlying method throws an exception. @exception NullPointerException if the specified object is null and the method is an instance method. @exception ExceptionInInitializerError if the initialization provoked by this method fails.
The Modifier class provides static
methods and constants to decode class and member access modifiers. The sets of modifiers are represented as integers with distinct bit positions representing different modifiers. The values for the constants representing the modifiers are taken from The JavaTM Virtual Machine Specification Second edition tables 4.1 4.4 4.5 and 4.7. @see Class#getModifiers() @see Member#getModifiers() @author Nakul Saraiya @author Kenneth Russell
Class Modifier, boolean isAbstract(int)Return true if theClass Modifier, boolean isFinal(int)specifierinteger argument includes the abstract modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the abstract modifier; false otherwise.
Return true if theClass Modifier, boolean isInterface(int)specifiedinteger argument includes the final modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the final modifier; false otherwise.
Return true if theClass Modifier, boolean isNative(int)specifierinteger argument includes the interface modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the interface modifier; false otherwise.
Return true if theClass Modifier, boolean isPrivate(int)specifierinteger argument includes the native modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the native modifier; false otherwise.
Return true if theClass Modifier, boolean isProtected(int)specifierinteger argument includes the private modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the private modifier; false otherwise.
Return true if theClass Modifier, boolean isPublic(int)specifierinteger argument includes the protected modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the protected modifier; false otherwise.
Return true if theClass Modifier, boolean isStatic(int)specifiedinteger argument includes the public modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the public modifier; false otherwise.
Return true if theClass Modifier, boolean isStrict(int)specifierinteger argument includes the static modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the static modifier; false otherwise.
Return true if theClass Modifier, boolean isSynchronized(int)specifierinteger argument includes the strictfp modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the strictfp modifier; false otherwise.
Return true if theClass Modifier, boolean isTransient(int)specifiedinteger argument includes the synchronized modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the synchronized modifier; false otherwise.
Return true if theClass Modifier, boolean isVolatile(int)specifierinteger argument includes the transient modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the transient modifier; false otherwise.
Return true if theClass Modifier, String toString(int)specifiedinteger argument includes the volatile modifer false otherwise. @param mod a set of modifers @return true ifmod
includes the volatile modifier; false otherwise.
Return a string describing the access modifier flags in the specified modifier. For example:The modifier names arepublic final synchronizedprivate transientstrictfpvolatilereturnreturned incanonicalan orderas specifiedconsistent withbythe suggested modifier orderings given in The Java Language Specification Second Edition sections §8.1.1 §8.3.1 §8.4.3 §8.8.3 and §9.1.1. The full modifier ordering used by this method is:Thepublic protected private abstract static final transient volatile synchronized native strictfp interface
interface
modifier discussed in this class is not a true modifier in the Java language and it appears after all other modifiers listed by this method. This method may return a string of modifiers that are not valid modifiers of a Java entity; in other words no checking is done on the possible validity of the combination of modifiers represented by the input. @param mod a set of modifers @return a string representation of the set of modifers represented bymod
Proxy
provides static methods for creating dynamic proxy classes and instances and it is also the superclass of all dynamic proxy classes created by those methods.To create a proxy for some interface
Foo
:InvocationHandler handler = new MyInvocationHandler(...); Class proxyClass = Proxy.getProxyClass( Foo.class.getClassLoader() new Class[] { Foo.class }); Foo f = (Foo) proxyClass. getConstructor(new Class[] { InvocationHandler.class }). newInstance(new Object[] { handler });or more simply:Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader() new Class[] { Foo.class } handler);A dynamic proxy class (simply referred to as a proxy class below) is a class that implements a list of interfaces specified at runtime when the class is created with behavior as described below. A proxy interface is such an interface that is implemented by a proxy class. A proxy instance is an instance of a proxy class. Each proxy instance has an associated invocation handler object which implements the interface InvocationHandler A method invocation on a proxy instance through one of its proxy interfaces will be dispatched to the invoke method of the instance's invocation handler passing the proxy instance a
java.lang.reflect.Method
object identifying the method that was invoked and an array of typeObject
containing the arguments. The invocation handler processes the encoded method invocation as appropriate and the result that it returns will be returned as the result of the method invocation on the proxy instance.A proxy class has the following properties:
- Proxy classes are public final and not abstract.
- The unqualified name of a proxy class is unspecified. The space of class names that begin with the string
"$Proxy"
should be however reserved for proxy classes.- A proxy class extends
java.lang.reflect.Proxy
.- A proxy class implements exactly the interfaces specified at its creation in the same order.
- If a proxy class implements a non-public interface then it will be defined in the same package as that interface. Otherwise the package of a proxy class is also unspecified. Note that package sealing will not prevent a proxy class from being successfully defined in a particular package at runtime and neither will classes already defined in the same class loader and the same package with particular signers.
- Since a proxy class implements all of the interfaces specified at its creation invoking
getInterfaces
on itsClass
object will return an array containing the same list of interfaces (in the order specified at its creation) invokinggetMethods
on itsClass
object will return an array ofMethod
objects that include all of the methods in those interfaces and invokinggetMethod
will find methods in the proxy interfaces as would be expected.- The Proxy.isProxyClass method will return true if it is passed a proxy class-- a class returned by
Proxy.getProxyClass
or the class of an object returned byProxy.newProxyInstance
-- and false otherwise.- The
java.security.ProtectionDomain
of a proxy class is the same as that of system classes loaded by the bootstrap class loader such asjava.lang.Object
because the code for a proxy class is generated by trusted system code. This protection domain will typically be grantedjava.security.AllPermission
.- Each proxy class has one public constructor that takes one argument an implementation of the interface InvocationHandler to set the invocation handler for a proxy instance. Rather than having to use the reflection API to access the public constructor a proxy instance can be also be created by calling the Proxy.newInstance method which combines the actions of calling Proxy.getProxyClass with invoking the constructor with an invocation handler.
A proxy instance has the following properties:
- Given a proxy instance
proxy
and one of the interfaces implemented by its proxy classFoo
the following expression will return true:and the following cast operation will succeed (rather than throwing aproxy instanceof Foo
ClassCastException
):(Foo) proxy
- Each proxy instance has an associated invocation handler the one that was passed to its constructor. The static Proxy.getInvocationHandler method will return the invocation handler associated with the proxy instance passed as its argument.
- An interface method invocation on a proxy instance will be encoded and dispatched to the invocation handler's invoke method as described in the documentation for that method.
- An invocation of the
hashCode
equals
ortoString
methods declared injava.lang.Object
on a proxy instance will be encoded and dispatched to the invocation handler'sinvoke
method in the same manner as interface method invocations are encoded and dispatched as described above. The declaring class of theMethod
object passed toinvoke
will bejava.lang.Object
. Other public methods of a proxy instance inherited fromjava.lang.Object
are not overridden by a proxy class so invocations of those methods behave like they do for instances ofjava.lang.Object
.Methods Duplicated in Multiple Proxy Interfaces
When two or more interfaces of a proxy class contain a method with the same name and parameter signature the order of the proxy class's interfaces becomes significant. When such a duplicate method is invoked on a proxy instance the
Method
object passed to the invocation handler will not necessarily be the one whose declaring class is assignable from the reference type of the interface that the proxy's method was invoked through. This limitation exists because the corresponding method implementation in the generated proxy class cannot determine which interface it was invoked through. Therefore when a duplicate method is invoked on a proxy instance theMethod
object for the method in the foremost interface that contains the method (either directly or inherited through a superinterface) in the proxy class's list of interfaces is passed to the invocation handler'sinvoke
method regardless of the reference type through which the method invocation occurred.If a proxy interface contains a method with the same name and parameter signature as the
hashCode
equals
ortoString
methods ofjava.lang.Object
when such a method is invoked on a proxy instance theMethod
object passed to the invocation handler will havejava.lang.Object
as its declaring class. In other words the public non-final methods ofjava.lang.Object
logically precede all of the proxy interfaces for the determination of whichMethod
object to pass to the invocation handler.Note also that when a duplicate method is dispatched to an invocation handler the
invoke
method may only throw checked exception types that are assignable to one of the exception types in thethrows
clause of the method in all of the proxy interfaces that it can be invoked through. If theinvoke
method throws a checked exception that is not assignable to any of the exception types declared by the method in one of the the proxy interfaces that it can be invoked through then an uncheckedUndeclaredThrowableException
will be thrown by the invocation on the proxy instance. This restriction means that not all of the exception types returned by invokinggetExceptionTypes
on theMethod
object passed to theinvoke
method can necessarily be thrown successfully by theinvoke
method. @author Peter Jones @version 1.8 009 01/0212/0203 @see InvocationHandler @since JDK1.3
Thrown by a method invocation on a proxy instance if its invocation handler's invoke method throws a checked exception (aClass UndeclaredThrowableException, constructor UndeclaredThrowableException(Throwable)Throwable
that is not assignable toRuntimeException
orError
) that is not assignable to any of the exception types declared in thethrows
clause of the method that was invoked on the proxy instance and dispatched to the invocation handler.An
UndeclaredThrowableException
instance contains the undeclared checked exception that was thrown by the invocation handler and it can be retrieved with thegetUndeclaredThrowable()
method.UndeclaredThrowableException
extendsRuntimeException
so it is an unchecked exception that wraps a checked exception.As of release 1.4 this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "undeclared checked exception that was thrown by the invocation handler" that may be provided at construction time and accessed via the #getUndeclaredThrowable() method is now known as the cause and may be accessed via the Throwable#getCause() method as well as the aforementioned "legacy method." @author Peter Jones @version 1.
6 0010 01/0212/0203 @see InvocationHandler @since JDK1.3
Constructs anClass UndeclaredThrowableException, Throwable getUndeclaredThrowable()UndeclaredThrowableException
with thespecifedspecifiedThrowable
. @param undeclaredThrowable the undeclared checked exception that was thrown
Returns theThrowable
instance wrapped in thisUndeclaredThrowableException
which may be null.This method predates the general-purpose exception chaining facility. The Throwable#getCause() method is now the preferred means of obtaining this information
. @return the undeclared checked exception that was thrown