public final class ArrayTypeUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Class<?> |
createArrayClass(Class<?> componentType)
Returns an array class of the given component type, e.g.
|
static Class<?> |
createArrayClass(Class<?> componentType,
int dimension)
Returns an array class of the given component type and with the given dimensions, e.g.
|
static Type |
createArrayType(Type componentType)
Returns an array class or a
GenericArrayType instance whose component type is the componentType
argument. |
static Type |
createArrayType(Type componentType,
int dimension)
Returns an array class or a generic array type whose component is the provided component type and
with the given dimension.
|
static ArrayTypeProperties |
getArrayProperty(Type type)
Returns a description of the given array type, or an array property with dimension 0
if it is not an array.
|
public static Class<?> createArrayClass(Class<?> componentType)
String.class,
then String[].class is returned.
As of Java 12, you can use componentType.arrayType().
componentType - the component type of the arrayIllegalArgumentException - if the component type is void.classpublic static Class<?> createArrayClass(Class<?> componentType, int dimension)
double.class and the dimension is 3, then double[][][].class is returned.componentType - the component type of the arraydimension - the dimension of the class (may not be negative)IllegalArgumentException - if the dimension is negative, or if the component type is void.classpublic static Type createArrayType(Type componentType)
GenericArrayType instance whose component type is the componentType
argument.
This method does not validate the component type, making it possible to create generic array types that might not
make sense or that may never be provided by the JDK. The JDK specifies that the component of a generic array type
is either a parameterized type or a
type variable.
componentType - the component type to create an array type forIllegalArgumentException - if the dimension is negative, or if the component type is void.classpublic static Type createArrayType(Type componentType, int dimension)
This method does not validate the component type, making it possible to create generic array types that might not
make sense or that may never be provided by the JDK. The JDK specifies that the component of a generic array type
is either a parameterized type or a
type variable.
componentType - the component typedimension - the dimension of the array (may not be negative)IllegalArgumentException - if the dimension is negative, or if the component type is void.classpublic static ArrayTypeProperties getArrayProperty(Type type)
type - the type to inspectCopyright © 2023. All rights reserved.