Friday, June 6, 2008

java.lang.reflect
Class Array
java.lang.Object
java.lang.reflect.Array

public final class Arrayextends Object
The Array class provides static methods to dynamically create and access Java arrays.
Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur.


Method Summary
static Object
get(Object array, int index)
Returns the value of the indexed component in the specified array object.
static boolean
getBoolean(Object array, int index)
Returns the value of the indexed component in the specified array object, as a boolean.
static byte
getByte(Object array, int index)
Returns the value of the indexed component in the specified array object, as a byte.
static char
getChar(Object array, int index)
Returns the value of the indexed component in the specified array object, as a char.
static double
getDouble(Object array, int index)
Returns the value of the indexed component in the specified array object, as a double.
static float
getFloat(Object array, int index)
Returns the value of the indexed component in the specified array object, as a float.
static int
getInt(Object array, int index)
Returns the value of the indexed component in the specified array object, as an int.
static int
getLength(Object array)
Returns the length of the specified array object, as an int.
static long
getLong(Object array, int index)
Returns the value of the indexed component in the specified array object, as a long.
static short
getShort(Object array, int index)
Returns the value of the indexed component in the specified array object, as a short.
static Object
newInstance(Class componentType, int length)
Creates a new array with the specified component type and length.
static Object
newInstance(Class componentType, int[] dimensions)
Creates a new array with the specified component type and dimensions.
static void
set(Object array, int index, Object value)
Sets the value of the indexed component of the specified array object to the specified new value.
static void
setBoolean(Object array, int index, boolean z)
Sets the value of the indexed component of the specified array object to the specified boolean value.
static void
setByte(Object array, int index, byte b)
Sets the value of the indexed component of the specified array object to the specified byte value.
static void
setChar(Object array, int index, char c)
Sets the value of the indexed component of the specified array object to the specified char value.
static void
setDouble(Object array, int index, double d)
Sets the value of the indexed component of the specified array object to the specified double value.
static void
setFloat(Object array, int index, float f)
Sets the value of the indexed component of the specified array object to the specified float value.
static void
setInt(Object array, int index, int i)
Sets the value of the indexed component of the specified array object to the specified int value.
static void
setLong(Object array, int index, long l)
Sets the value of the indexed component of the specified array object to the specified long value.
static void
setShort(Object array, int index, short s)
Sets the value of the indexed component of the specified array object to the specified short value.

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Method Detail
newInstance
public static Object newInstance(Class componentType,
int length)
throws NegativeArraySizeException
Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:
int[] x = {length};
Array.newInstance(componentType, x);

Parameters:
componentType - the Class object representing the component type of the new array
length - the length of the new array
Returns:
the new array
Throws:
NullPointerException - if the specified componentType parameter is null
IllegalArgumentException - if componentType is Void.TYPE
NegativeArraySizeException - if the specified length is negative

newInstance
public static Object newInstance(Class componentType,
int[] dimensions)
throws IllegalArgumentException,
NegativeArraySizeException
Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType. In this case, the component type of the new array is the component type of componentType.
The number of dimensions of the new array must not exceed the number of array dimensions supported by the implementation (typically 255).
Parameters:
componentType - the Class object representing the component type of the new array
dimensions - an array of int types representing the dimensions of the new array
Returns:
the new array
Throws:
NullPointerException - if the specified componentType argument is null
IllegalArgumentException - if the specified dimensions 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.
NegativeArraySizeException - if any of the components in the specified dimensions argument is negative.

getLength
public static int getLength(Object array)
throws IllegalArgumentException
Returns the length of the specified array object, as an int.
Parameters:
array - the array
Returns:
the length of the array
Throws:
IllegalArgumentException - if the object argument is not an array

get
public static Object get(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object. The value is automatically wrapped in an object if it has a primitive type.
Parameters:
array - the array
index - the index
Returns:
the (possibly wrapped) value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getBoolean
public static boolean getBoolean(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a boolean.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getByte
public static byte getByte(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a byte.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getChar
public static char getChar(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a char.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getShort
public static short getShort(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a short.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getInt
public static int getInt(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as an int.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getLong
public static long getLong(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a long.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getFloat
public static float getFloat(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a float.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

getDouble
public static double getDouble(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified array object, as a double.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws:
NullPointerException - If the specified object is null
IllegalArgumentException - If the specified object is not an array, or if the indexed element cannot be converted to the return type by an identity or widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
get(java.lang.Object, int)

set
public static void set(Object array,
int index,
Object value)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified new value. The new value is first automatically unwrapped if the array has a primitive component type.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the array component type is primitive and an unwrapping conversion fails
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setBoolean
public static void setBoolean(Object array,
int index,
boolean z)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified boolean value.
Parameters:
array - the array
index - the index into the array
z - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setByte
public static void setByte(Object array,
int index,
byte b)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified byte value.
Parameters:
array - the array
index - the index into the array
b - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setChar
public static void setChar(Object array,
int index,
char c)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified char value.
Parameters:
array - the array
index - the index into the array
c - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setShort
public static void setShort(Object array,
int index,
short s)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified short value.
Parameters:
array - the array
index - the index into the array
s - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setInt
public static void setInt(Object array,
int index,
int i)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified int value.
Parameters:
array - the array
index - the index into the array
i - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setLong
public static void setLong(Object array,
int index,
long l)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified long value.
Parameters:
array - the array
index - the index into the array
l - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setFloat
public static void setFloat(Object array,
int index,
float f)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified float value.
Parameters:
array - the array
index - the index into the array
f - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)

setDouble
public static void setDouble(Object array,
int index,
double d)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified double value.
Parameters:
array - the array
index - the index into the array
d - the new value of the indexed component
Throws:
NullPointerException - If the specified object argument is null
IllegalArgumentException - If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException - If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
See Also:
set(java.lang.Object, int, java.lang.Object)
java.lang.reflect
Class Method
java.lang.Object
java.lang.reflect.AccessibleObject
java.lang.reflect.Method
All Implemented Interfaces:
AnnotatedElement, GenericDeclaration, Member

public final class Methodextends AccessibleObjectimplements GenericDeclaration, Member
A 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 invoke with the underlying method's formal parameters, but it throws an IllegalArgumentException if a narrowing conversion would occur.
See Also:
Member, Class, Class.getMethods(), Class.getMethod(String, Class[]), Class.getDeclaredMethods(), Class.getDeclaredMethod(String, Class[])


Field Summary

Fields inherited from interface java.lang.reflect.Member
DECLARED, PUBLIC

Method Summary
boolean
equals(Object obj)
Compares this Method against the specified object.


T


getAnnotation(Class annotationClass)
Returns this element's annotation for the specified type if such an annotation is present, else null.
Annotation[]
getDeclaredAnnotations()
Returns all annotations that are directly present on this element.
Class
getDeclaringClass()
Returns the Class object representing the class or interface that declares the method represented by this Method object.
Object
getDefaultValue()
Returns the default value for the annotation member represented by this Method instance.
Class[]
getExceptionTypes()
Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this Method object.
Type[]
getGenericExceptionTypes()
Returns an array of Type objects that represent the exceptions declared to be thrown by this Method object.
Type[]
getGenericParameterTypes()
Returns an array of Type objects that represent the formal parameter types, in declaration order, of the method represented by this Method object.
Type
getGenericReturnType()
Returns a Type object that represents the formal return type of the method represented by this Method object.
int
getModifiers()
Returns the Java language modifiers for the method represented by this Method object, as an integer.
String
getName()
Returns the name of the method represented by this Method object, as a String.
Annotation[][]
getParameterAnnotations()
Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object.
Class[]
getParameterTypes()
Returns an array of Class objects that represent the formal parameter types, in declaration order, of the method represented by this Method object.
Class
getReturnType()
Returns a Class object that represents the formal return type of the method represented by this Method object.
TypeVariable[]
getTypeParameters()
Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order.
int
hashCode()
Returns a hashcode for this Method.
Object
invoke(Object obj, Object... args)
Invokes the underlying method represented by this Method object, on the specified object with the specified parameters.
boolean
isBridge()
Returns true if this method is a bridge method; returns false otherwise.
boolean
isSynthetic()
Returns true if this method is a synthetic method; returns false otherwise.
boolean
isVarArgs()
Returns true if this method was declared to take a variable number of arguments; returns false otherwise.
String
toGenericString()
Returns a string describing this Method, including type parameters.
String
toString()
Returns a string describing this Method.

Methods inherited from class java.lang.reflect.AccessibleObject
getAnnotations, isAccessible, isAnnotationPresent, setAccessible, setAccessible

Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait


Method Detail
getDeclaringClass
public Class getDeclaringClass()
Returns the Class object representing the class or interface that declares the method represented by this Method object.
Specified by:
getDeclaringClass in interface Member
Returns:
an object representing the declaring class of the underlying member

getName
public String getName()
Returns the name of the method represented by this Method object, as a String.
Specified by:
getName in interface Member
Returns:
the simple name of the underlying member

getModifiers
public int getModifiers()
Returns the Java language modifiers for the method represented by this Method object, as an integer. The Modifier class should be used to decode the modifiers.
Specified by:
getModifiers in interface Member
Returns:
the Java language modifiers for the underlying member
See Also:
Modifier

getTypeParameters
public TypeVariable[] getTypeParameters()
Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order. Returns an array of length 0 if the underlying generic declaration declares no type variables.
Specified by:
getTypeParameters in interface GenericDeclaration
Returns:
an array of TypeVariable objects that represent the type variables declared by this generic declaration
Throws:
GenericSignatureFormatError - if the generic signature of this generic declaration does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
Since:
1.5

getReturnType
public Class getReturnType()
Returns a Class object that represents the formal return type of the method represented by this Method object.
Returns:
the return type for the method this object represents

getGenericReturnType
public Type getGenericReturnType()
Returns a Type object that represents the formal return type of the method represented by this Method object.
If the return type is a parameterized type, the Type object returned must accurately reflect the actual type parameters used in the source code.
If the return type is a type variable or a parameterized type, it is created. Otherwise, it is resolved.
Returns:
a Type object that represents the formal return type of the underlying method
Throws:
GenericSignatureFormatError - if the generic method signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
TypeNotPresentException - if the underlying method's return type refers to a non-existent type declaration
MalformedParameterizedTypeException - if the underlying method's return typed refers to a parameterized type that cannot be instantiated for any reason
Since:
1.5

getParameterTypes
public Class[] getParameterTypes()
Returns an array of Class objects that represent the formal parameter types, in declaration order, of the method represented by this Method object. Returns an array of length 0 if the underlying method takes no parameters.
Returns:
the parameter types for the method this object represents

getGenericParameterTypes
public Type[] getGenericParameterTypes()
Returns an array of Type objects that represent the formal parameter types, in declaration order, of the method represented by this Method object. Returns an array of length 0 if the underlying method takes no parameters.
If a formal parameter type is a parameterized type, the Type object returned for it must accurately reflect the actual type parameters used in the source code.
If a formal parameter type is a type variable or a parameterized type, it is created. Otherwise, it is resolved.
Returns:
an array of Types that represent the formal parameter types of the underlying method, in declaration order
Throws:
GenericSignatureFormatError - if the generic method signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
TypeNotPresentException - if any of the parameter types of the underlying method refers to a non-existent type declaration
MalformedParameterizedTypeException - if any of the underlying method's parameter types refer to a parameterized type that cannot be instantiated for any reason
Since:
1.5

getExceptionTypes
public Class[] getExceptionTypes()
Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this Method object. Returns an array of length 0 if the method declares no exceptions in its throws clause.
Returns:
the exception types declared as being thrown by the method this object represents

getGenericExceptionTypes
public Type[] getGenericExceptionTypes()
Returns an array of Type objects that represent the exceptions declared to be thrown by this Method object. Returns an array of length 0 if the underlying method declares no exceptions in its throws clause.
If an exception type is a parameterized type, the Type object returned for it must accurately reflect the actual type parameters used in the source code.
If an exception type is a type variable or a parameterized type, it is created. Otherwise, it is resolved.
Returns:
an array of Types that represent the exception types thrown by the underlying method
Throws:
GenericSignatureFormatError - if the generic method signature does not conform to the format specified in the Java Virtual Machine Specification, 3rd edition
TypeNotPresentException - if the underlying method's throws clause refers to a non-existent type declaration
MalformedParameterizedTypeException - if the underlying method's throws clause refers to a parameterized type that cannot be instantiated for any reason
Since:
1.5

equals
public boolean equals(Object obj)
Compares this Method against the specified object. Returns true if the objects are the same. Two Methods are the same if they were declared by the same class and have the same name and formal parameter types and return type.
Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode(), Hashtable

hashCode
public int hashCode()
Returns a hashcode for this Method. The hashcode is computed as the exclusive-or of the hashcodes for the underlying method's declaring class name and the method's name.
Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable

toString
public String toString()
Returns a string describing this Method. The string is formatted as the method access modifiers, if any, followed by the method return type, followed by a space, followed by the class declaring the method, followed by a period, followed by the method name, followed by a parenthesized, comma-separated list of the method's formal parameter types. If the method throws checked exceptions, the parameter list is followed by a space, followed by the word throws followed by a comma-separated list of the thrown exception types. For example:
public boolean java.lang.Object.equals(java.lang.Object)

The access modifiers are placed in canonical order as specified by "The Java Language Specification". This is public, protected or private first, and then other modifiers in the following order: abstract, static, final, synchronized native.
Overrides:
toString in class Object
Returns:
a string representation of the object.

toGenericString
public String toGenericString()
Returns a string describing this Method, including type parameters. The string is formatted as the method access modifiers, if any, followed by an angle-bracketed comma-separated list of the method's type parameters, if any, followed by the method's generic return type, followed by a space, followed by the class declaring the method, followed by a period, followed by the method name, followed by a parenthesized, comma-separated list of the method's generic formal parameter types. A space is used to separate access modifiers from one another and from the type parameters or return type. If there are no type parameters, the type parameter list is elided; if the type parameter list is present, a space separates the list from the class name. If the method is declared to throw exceptions, the parameter list is followed by a space, followed by the word throws followed by a comma-separated list of the generic thrown exception types. If there are no type parameters, the type parameter list is elided.
The access modifiers are placed in canonical order as specified by "The Java Language Specification". This is public, protected or private first, and then other modifiers in the following order: abstract, static, final, synchronized native.
Returns:
a string describing this Method, include type parameters
Since:
1.5

invoke
public Object invoke(Object obj,
Object... args)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException
Invokes the underlying method represented by this Method 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 to method invocation conversions as necessary.
If the underlying method is static, then the specified obj argument is ignored. It may be null.
If the number of formal parameters required by the underlying method is 0, the supplied args array may be of length 0 or null.
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.12.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.
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. However, if the value has the type of an array of a primitive type, the elements of the array are not wrapped in objects; in other words, an array of primitive type is returned. If the underlying method return type is void, the invocation returns null.
Parameters:
obj - the object the underlying method is invoked from
args - the arguments used for the method call
Returns:
the result of dispatching the method represented by this object on obj with parameters args
Throws:
IllegalAccessException - if this Method object enforces Java language access control and the underlying method is inaccessible.
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 differ; 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.
InvocationTargetException - if the underlying method throws an exception.
NullPointerException - if the specified object is null and the method is an instance method.
ExceptionInInitializerError - if the initialization provoked by this method fails.

isBridge
public boolean isBridge()
Returns true if this method is a bridge method; returns false otherwise.
Returns:
true if and only if this method is a bridge method as defined by the Java Language Specification.
Since:
1.5

isVarArgs
public boolean isVarArgs()
Returns true if this method was declared to take a variable number of arguments; returns false otherwise.
Returns:
true if an only if this method was declared to take a variable number of arguments.
Since:
1.5

isSynthetic
public boolean isSynthetic()
Returns true if this method is a synthetic method; returns false otherwise.
Specified by:
isSynthetic in interface Member
Returns:
true if and only if this method is a synthetic method as defined by the Java Language Specification.
Since:
1.5

getAnnotation
public T getAnnotation(Class annotationClass)
Description copied from interface: AnnotatedElement
Returns this element's annotation for the specified type if such an annotation is present, else null.
Specified by:
getAnnotation in interface AnnotatedElement
Overrides:
getAnnotation in class AccessibleObject
Parameters:
annotationClass - the Class object corresponding to the annotation type
Returns:
this element's annotation for the specified annotation type if present on this element, else null

getDeclaredAnnotations
public Annotation[] getDeclaredAnnotations()
Description copied from interface: AnnotatedElement
Returns all annotations that are directly present on this element. Unlike the other methods in this interface, this method ignores inherited annotations. (Returns an array of length zero if no annotations are directly present on this element.) The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.
Specified by:
getDeclaredAnnotations in interface AnnotatedElement
Overrides:
getDeclaredAnnotations in class AccessibleObject
Returns:
All annotations directly present on this element

getDefaultValue
public Object getDefaultValue()
Returns the default value for the annotation member represented by this Method instance. If the member is of a primitive type, an instance of the corresponding wrapper type is returned. Returns null if no default is associated with the member, or if the method instance does not represent a declared member of an annotation type.
Returns:
the default value for the annotation member represented by this Method instance.
Throws:
TypeNotPresentException - if the annotation is of type Class and no definition can be found for the default class value.
Since:
1.5

getParameterAnnotations
public Annotation[][] getParameterAnnotations()
Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object. (Returns an array of length zero if the underlying method is parameterless. If the method has one or more parameters, a nested array of length zero is returned for each parameter with no annotations.) The annotation objects contained in the returned arrays are serializable. The caller of this method is free to modify the returned arrays; it will have no effect on the arrays returned to other callers.
Returns:
an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object
Since:
1.5
java.beans
Class Beans
java.lang.Object
java.beans.Beans

public class Beansextends Object
This class provides some general purpose beans control methods.


Constructor Summary
Beans()



Method Summary
static Object
getInstanceOf(Object bean, Class targetType)
From a given bean, obtain an object representing a specified type view of that source object.
static Object
instantiate(ClassLoader cls, String beanName)
Instantiate a JavaBean.
static Object
instantiate(ClassLoader cls, String beanName, BeanContext beanContext)
Instantiate a JavaBean.
static Object
instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
Instantiate a bean.
static boolean
isDesignTime()
Test if we are in design-mode.
static boolean
isGuiAvailable()
Determines whether beans can assume a GUI is available.
static boolean
isInstanceOf(Object bean, Class targetType)
Check if a bean can be viewed as a given target type.
static void
setDesignTime(boolean isDesignTime)
Used to indicate whether of not we are running in an application builder environment.
static void
setGuiAvailable(boolean isGuiAvailable)
Used to indicate whether of not we are running in an environment where GUI interaction is available.

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait


Constructor Detail
Beans
public Beans()

Method Detail
instantiate
public static Object instantiate(ClassLoader cls,
String beanName)
throws IOException,
ClassNotFoundException
Instantiate a JavaBean.
Parameters:
cls - the class-loader from which we should create the bean. If this is null, then the system class-loader is used.
beanName - the name of the bean within the class-loader. For example "sun.beanbox.foobah"
Throws:
ClassNotFoundException - if the class of a serialized object could not be found.
IOException - if an I/O error occurs.

instantiate
public static Object instantiate(ClassLoader cls,
String beanName,
BeanContext beanContext)
throws IOException,
ClassNotFoundException
Instantiate a JavaBean.
Parameters:
cls - the class-loader from which we should create the bean. If this is null, then the system class-loader is used.
beanName - the name of the bean within the class-loader. For example "sun.beanbox.foobah"
beanContext - The BeanContext in which to nest the new bean
Throws:
ClassNotFoundException - if the class of a serialized object could not be found.
IOException - if an I/O error occurs.

instantiate
public static Object instantiate(ClassLoader cls,
String beanName,
BeanContext beanContext,
AppletInitializer initializer)
throws IOException,
ClassNotFoundException
Instantiate a bean.
The bean is created based on a name relative to a class-loader. This name should be a dot-separated name such as "a.b.c".
In Beans 1.0 the given name can indicate either a serialized object or a class. Other mechanisms may be added in the future. In beans 1.0 we first try to treat the beanName as a serialized object name then as a class name.
When using the beanName as a serialized object name we convert the given beanName to a resource pathname and add a trailing ".ser" suffix. We then try to load a serialized object from that resource.
For example, given a beanName of "x.y", Beans.instantiate would first try to read a serialized object from the resource "x/y.ser" and if that failed it would try to load the class "x.y" and create an instance of that class.
If the bean is a subtype of java.applet.Applet, then it is given some special initialization. First, it is supplied with a default AppletStub and AppletContext. Second, if it was instantiated from a classname the applet's "init" method is called. (If the bean was deserialized this step is skipped.)
Note that for beans which are applets, it is the caller's responsiblity to call "start" on the applet. For correct behaviour, this should be done after the applet has been added into a visible AWT container.
Note that applets created via beans.instantiate run in a slightly different environment than applets running inside browsers. In particular, bean applets have no access to "parameters", so they may wish to provide property get/set methods to set parameter values. We advise bean-applet developers to test their bean-applets against both the JDK appletviewer (for a reference browser environment) and the BDK BeanBox (for a reference bean container).
Parameters:
cls - the class-loader from which we should create the bean. If this is null, then the system class-loader is used.
beanName - the name of the bean within the class-loader. For example "sun.beanbox.foobah"
beanContext - The BeanContext in which to nest the new bean
initializer - The AppletInitializer for the new bean
Throws:
ClassNotFoundException - if the class of a serialized object could not be found.
IOException - if an I/O error occurs.

getInstanceOf
public static Object getInstanceOf(Object bean,
Class targetType)
From a given bean, obtain an object representing a specified type view of that source object.
The result may be the same object or a different object. If the requested target view isn't available then the given bean is returned.
This method is provided in Beans 1.0 as a hook to allow the addition of more flexible bean behaviour in the future.
Parameters:
bean - Object from which we want to obtain a view.
targetType - The type of view we'd like to get.

isInstanceOf
public static boolean isInstanceOf(Object bean,
Class targetType)
Check if a bean can be viewed as a given target type. The result will be true if the Beans.getInstanceof method can be used on the given bean to obtain an object that represents the specified targetType type view.
Parameters:
bean - Bean from which we want to obtain a view.
targetType - The type of view we'd like to get.
Returns:
"true" if the given bean supports the given targetType.

isDesignTime
public static boolean isDesignTime()
Test if we are in design-mode.
Returns:
True if we are running in an application construction environment.
See Also:
DesignMode

isGuiAvailable
public static boolean isGuiAvailable()
Determines whether beans can assume a GUI is available.
Returns:
True if we are running in an environment where beans can assume that an interactive GUI is available, so they can pop up dialog boxes, etc. This will normally return true in a windowing environment, and will normally return false in a server environment or if an application is running as part of a batch job.
See Also:
Visibility

setDesignTime
public static void setDesignTime(boolean isDesignTime)
throws SecurityException
Used to indicate whether of not we are running in an application builder environment.
Note that this method is security checked and is not available to (for example) untrusted applets. More specifically, if there is a security manager, its checkPropertiesAccess method is called. This could result in a SecurityException.
Parameters:
isDesignTime - True if we're in an application builder tool.
Throws:
SecurityException - if a security manager exists and its checkPropertiesAccess method doesn't allow setting of system properties.
See Also:
SecurityManager.checkPropertiesAccess()

setGuiAvailable
public static void setGuiAvailable(boolean isGuiAvailable)
throws SecurityException
Used to indicate whether of not we are running in an environment where GUI interaction is available.
Note that this method is security checked and is not available to (for example) untrusted applets. More specifically, if there is a security manager, its checkPropertiesAccess method is called. This could result in a SecurityException.
Parameters:
isGuiAvailable - True if GUI interaction is available.
Throws:
SecurityException - if a security manager exists and its checkPropertiesAccess method doesn't allow setting of system properties.
See Also:
SecurityManager.checkPropertiesAccess()