Class ReflectionUtil

java.lang.Object
com.pervasive.datarush.commons.util.ReflectionUtil

public final class ReflectionUtil extends Object
Utility methods related to reflection.
  • Method Details

    • getWrapperForPrimitiveType

      public static Class<?> getWrapperForPrimitiveType(Class<?> primitive)
      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 to Class.forName(name,initialize,loader), but handles primitive types as well.
      Parameters:
      name - The name of the class to load
      initialize - whether the class must be initialized
      loader - 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

      public static <F> F[] newArray(Class<F> componentType, int length)
      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

      public static <F> F[] arraycast(Class<F> componentType, Object[] array)
      Casts the given array to an array of the specified component type.
      Type Parameters:
      F - The component type
      Parameters:
      componentType - The component type
      array - 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.