public final class ReflectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <F> F[] |
arraycast(Class<F> componentType,
Object[] array)
Casts the given array to an array of the specified component type.
|
static Class<?> |
classForName(String name,
boolean initialize,
ClassLoader loader)
Equivalent to
Class.forName(name,initialize,loader) , but
handles primitive types as well. |
static Class<?> |
getWrapperForPrimitiveType(Class<?> primitive)
Returns the wrapper type the given primitive type
|
static <F> F[] |
newArray(Class<F> componentType,
int length)
Creates a new array of the given component type.
|
public static Class<?> getWrapperForPrimitiveType(Class<?> primitive)
primitive
- the primitive classIllegalArgumentException
- if the given type is not primitivepublic static Class<?> classForName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException
Class.forName(name,initialize,loader)
, but
handles primitive types as well.name
- The name of the class to loadinitialize
- whether the class must be initializedloader
- class loader from which the class must be loadedClassNotFoundException
- if the class cannot be located by
the specified class loaderpublic static <F> F[] newArray(Class<F> componentType, int length)
F
- The component typecomponentType
- The component type. Must not be primitive.length
- The length of the array.public static <F> F[] arraycast(Class<F> componentType, Object[] array)
F
- The component typecomponentType
- The component typearray
- The original array. All elements of the array must be assignable to the component type.ClassCastException
- If any of the elements of the array are not assignable to the new component type.Copyright © 2021 Actian Corporation. All rights reserved.