Contents:
Array
Constructor
Field
InvocationTargetException
Member
Method
Modifier
The package java.lang.reflect is new as of Java 1.1. It contains classes and interfaces that support the Reflection API. Reflection refers to the ability of a class to reflect upon itself, or look inside of itself, to see what it can do. The Reflection API makes it possible to:
These capabilities are implemented by the java.lang.Class class and the classes in the java.lang.reflect package. Figure 13.1 shows the class hierarchy for the java.lang.reflect package.
Java 1.1 currently uses the Reflection API for two purposes:
java.lang.reflect.Array
java.lang.Object
None
java.lang.Cloneable, java.io.Serializable
New as of JDK 1.1
The Array class provides static methods to manipulate arbitrary arrays in Java. There are methods to set and retrieve elements in an array, determine the size of an array, and create a new instance of an array.
The Array class is used to create array objects and manipulate their elements. The Array class is not used to represent array types. Because arrays in Java are objects, array types are represented by Class objects.
public final class java.lang.reflect.Array extends java.lang.Object { // Class Methods public static native Object get(Object array, int index); public static native boolean getBoolean(Object array, int index); public static native byte getByte(Object array, int index); public static native char getChar(Object array, int index); public static native double getDouble(Object array, int index); public static native float getFloat(Object array, int index); public static native int getInt(Object array, int index); public static native int getLength(Object array); public static native long getLong(Object array, int index); public static native short getShort(Object array, int index); public static Object newInstance(Class componentType, int length); public static Object newInstance(Class componentType, int[] dimensions); public static native void set(Object array, int index, Object value); public static native void setBoolean(Object array, int index, boolean z); public static native void setByte(Object array, int index, byte b); public static native void setChar(Object array, int index, char c); public static native void setDouble(Object array, int index, double d); public static native void setFloat(Object array, int index, float f); public static native void setInt(Object array, int index, int i); public static native void setLong(Object array, int index, long l); public static native void setShort(Object array, int index, short s); }
public static native Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The object at the given index in the specified array.
If the given object is not an array.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array. If the array contains values of a primitive type, the value at the given index is wrapped in an appropriate object, and the object is returned.
public static native boolean getBoolean(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The boolean value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a boolean.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a boolean value.
public static native byte getByte(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The byte value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a byte.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a byte value.
public static native char getChar(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The char value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a char.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a char value.
public static native double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The double value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a double.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a double value.
public static native float getFloat(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The float value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a float.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a float value.
public static native int getInt(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The int value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a int.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a int value.
public static native int getLength(Object array) throws IllegalArgumentException
An array object.
The length of the specified array.
If the given object is not an array.
This method returns the length of the array.
public static native long getLong(Object array, long index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The long value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a long.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a long value.
public static native short getShort(Object array, short index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The short value at the given index in the specified array.
If the given object is not an array, or the object at the given index cannot be converted to a short.
If the given index is invalid.
If array is null.
This method returns the object at the given index in the array as a short value.
public static Object newInstance(Class componentType, int length) throws NegativeArraySizeException
The type of each element in the array.
The length of the array.
An array object that contains elements of the given component type and has the specified length.
If length is negative.
If componentType is null.
This method creates a single-dimension array with the given length and component type.
public static Object newInstance(Class componentType, int[] dimensions) throws IllegalArgumentException, NegativeArraySizeException
The type of each element in the array.
An array that specifies the dimensions of the array to be created.
An array object that contains elements of the given component type and has the specified number of dimensions.
If dimensions has zero dimensions itself, or if it has too many dimensions (typically 255 array dimensions are supported).
If length is negative.
If componentType is null.
This method creates a multidimensional array with the given dimensions and component type.
public static native void set(Object array, int index, Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if it represents an array of primitive values, and the given value cannot be unwrapped and converted to that primitive type.
If the given index is invalid.
If array is null.
This method sets the object at the given index in the array to the specified value. If the array contains values of a primitive type, the given value is automatically unwrapped before it is put in the array.
public static native void setBoolean(Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given boolean value.
public static native void setByte(Object array, int index, byte b) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given byte value.
public static native void setChar(Object array, int index, char c) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given char value.
public static native void setDouble(Object array, int index, double d) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given double value.
public static native void setFloat(Object array, int index, float f) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given float value.
public static native void setInt(Object array, int index, int i) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given int value.
public static native void setLong(Object array, int index, long l) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given long value.
public static native void setShort(Object array, int index, short s) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
An array object.
An index into the array.
The new value.
If the given object is not an array, or if the given value cannot be converted to the component type of the array.
If the given index is invalid.
If array is null.
This method sets the element at the given index in the array to the given short value.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
ArrayIndexOutOfBoundsException, Class, IllegalArgumentException, NegativeArraySizeException, NullPointerException, Object