Package hec.lang

Class Reflection

java.lang.Object
hec.lang.Reflection

public class Reflection extends Object
A helper class for using reflection that allows using class names instead of Classes as parameters for retrieving Constructors, Methods, and Fields
  • Field Details

    • emptyParamTypes

      public static final String[] emptyParamTypes
      Constant for specifying absence of parameters in getConstructor() and getMethod()
    • emptyParams

      public static final Object[] emptyParams
      Constant for specifying absence of parameters in newInstance() and invoke()
  • Constructor Details

    • Reflection

      public Reflection()
  • Method Details

    • getClass

      public static Class<?> getClass(String name) throws Exception
      Returns the Class for a given name, including arrays and primitives

      Primitives are specified by their name (e.g., "char", "double")

      Arrays are specified as in declarations (e.g., "java.lang.String[]", "int[]")

      Parameters:
      name - The name of the class, array, or primitive
      Returns:
      The Class corresponding to the name
      Throws:
      Exception
    • getField

      public static Field getField(String className, String fieldName) throws Exception
      Returns the specified Field of a named Class
      Parameters:
      className - The name of the class from which to get the Field
      fieldName - The name of the Field to return
      Returns:
      the specified Field
      Throws:
      Exception
    • getConstructor

      public static Constructor<? extends Object> getConstructor(String className, String... paramTypes) throws Exception
      Returns the Constructor for a specified Class and parameter signature
      Parameters:
      className - The name of the class for which to return the Constructor
      paramTypes - An array specifying the parameter type names (as used by getClass())
      Returns:
      The Constructor for the specified class matching the parameter signature
      Throws:
      Exception
    • getConstructor

      public static Constructor<? extends Object> getConstructor(String className, String paramType) throws Exception
      Returns the Constructor for a specified Class and parameter signature
      Parameters:
      className - The name of the class for which to return the Constructor
      paramType - A single parameter type name (as used by getClass())
      Returns:
      The Constructor for the specified class matching the parameter signature
      Throws:
      Exception
    • getMethod

      public static Method getMethod(String className, String methodName, String... paramTypes) throws Exception
      Returns the Method for a specified Class, method name and parameter signature
      Parameters:
      className - The name of the class for which to return the Method
      methodName - The name of the Method to return
      paramTypes - An array specifying the parameter type names (as used by getClass())
      Returns:
      The Method for the specified class matching the method name and parameter signature
      Throws:
      Exception
    • getMethod

      public static Method getMethod(String className, String methodName, String paramType) throws Exception
      Returns the Method for a specified Class, method name and parameter signature
      Parameters:
      className - The name of the class for which to return the Method
      methodName - The name of the Method to return
      paramType - A single parameter type name (as used by getClass())
      Returns:
      The Method for the specified class matching the method name and parameter signature
      Throws:
      Exception