Java reflection array dynamically created array
@author Ixenos
Note: Java.lang.reflect.Array is a reflection toolkit, full of static methods, creating arrays based on multidimensional arrays, one-dimensional arrays are only special implementations
Creates a new array with the specified component type and length (one-dimensional array) Newinstance
newinstance (class<?> componenttype, int length) throws Negativearraysizeexception
-
Creates a new array with the specified component type and length. Calling this method is equivalent to creating the following array:
-
int[] x = {length}; To create an array based on a multidimensional array, a one-dimensional array is only a special implementation of Array.newinstance (ComponentType, x);
-
-
Parameters:
-
componentType -
Class object representing the component type of the new array
-
length -length of the new array
-
Return:
-
New array
-
Thrown:
-
NullPointerException -If the specified
componentType parameter is null
-
IllegalArgumentException -if ComponentType is
Void.TYPE
-
NegativeArraySizeException -if the specified
lengthis negative
-
Creates a new array with the specified component type and dimension (multidimensional array) Newinstance
newinstance (class<?> componenttype, int ... dimensions) throws IllegalArgumentException, Negativearraysizeexception
-
-
creates a new array with the specified component type and dimension.
-
-
if
componentType a non-array class or interface is represented, the new array has dimensions.length dimensions and is componentType used as its component type.
-
-
If you
componentType represent an array class, the dimensions of the new array are equal to dimensions.length componentType the sum of the dimensions of the number. in this case, the component type of the new array is
componentType the component type.
The dimension of the new array cannot exceed the number of array dimensions (typically 255)that the implementation supports.
-
-
-
Parameters:
-
componentType -
Class object representing the component type of the new array
-
dimensions -
int An array representing the new array dimension
-
Return:
-
New array
-
Thrown:
-
NullPointerException -If the specified
componentType argument is null
-
IllegalArgumentException -If the specified
dimensions parameter is an array of 0 dimensions, or the requested number of dimensions exceeds the limit of the number of array dimensions supported by the implementation (typically 2 25), or an array of degrees, or the number of dimensions requested exceeds the limit (usually 225) of the number of array dimensions supported by the implementation, or ComponentType
Void.TYPE .
-
NegativeArraySizeException -if
dimensions any component in the specified parameter is negative.
To create a multidimensional array example:
get(Object array, int index)returns the value of the index component in the specified Array object
setInt(Object array, int index, int i)sets the value of the index component in the specified array object to the specified int value.
Java reflection array dynamically created array