java.lang.Object
com.pervasive.datarush.commons.util.ReflectionUtil
Utility methods related to reflection.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <F> F[]Casts the given array to an array of the specified component type.static Class<?>classForName(String name, boolean initialize, ClassLoader loader) Equivalent toClass.forName(name,initialize,loader), but handles primitive types as well.static Class<?>getWrapperForPrimitiveType(Class<?> primitive) Returns the wrapper type the given primitive typestatic <F> F[]Creates a new array of the given component type.
-
Method Details
-
getWrapperForPrimitiveType
Returns the wrapper type the given primitive type- Parameters:
primitive- the primitive class- Returns:
- the wrapper type the given primitive type
- Throws:
IllegalArgumentException- if the given type is not primitive
-
classForName
public static Class<?> classForName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException Equivalent toClass.forName(name,initialize,loader), but handles primitive types as well.- Parameters:
name- The name of the class to loadinitialize- whether the class must be initializedloader- class loader from which the class must be loaded- Returns:
- class object representing the desired class
- Throws:
ClassNotFoundException- if the class cannot be located by the specified class loader
-
newArray
Creates a new array of the given component type.- Type Parameters:
F- The component type- Parameters:
componentType- The component type. Must not be primitive.length- The length of the array.- Returns:
- A new array of the given component type.
-
arraycast
Casts the given array to an array of the specified component type.- Type Parameters:
F- The component type- Parameters:
componentType- The component typearray- The original array. All elements of the array must be assignable to the component type.- Returns:
- A newly created array of the given type.
- Throws:
ClassCastException- If any of the elements of the array are not assignable to the new component type.
-