Package hec.lang
Class Reflection
java.lang.Object
hec.lang.Reflection
A helper class for using reflection that allows using class names instead of Classes
as parameters for retrieving Constructors, Methods, and Fields
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>
Returns the Class for a given name, including arrays and primitivesstatic Constructor<? extends Object>
getConstructor
(String className, String paramType) Returns the Constructor for a specified Class and parameter signaturestatic Constructor<? extends Object>
getConstructor
(String className, String... paramTypes) Returns the Constructor for a specified Class and parameter signaturestatic Field
Returns the specified Field of a named Classstatic Method
Returns the Method for a specified Class, method name and parameter signaturestatic Method
Returns the Method for a specified Class, method name and parameter signature
-
Field Details
-
emptyParamTypes
Constant for specifying absence of parameters in getConstructor() and getMethod() -
emptyParams
Constant for specifying absence of parameters in newInstance() and invoke()
-
-
Constructor Details
-
Reflection
public Reflection()
-
-
Method Details
-
getClass
Returns the Class for a given name, including arrays and primitivesPrimitives 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
Returns the specified Field of a named Class- Parameters:
className
- The name of the class from which to get the FieldfieldName
- 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 ConstructorparamTypes
- 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 ConstructorparamType
- 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 MethodmethodName
- The name of the Method to returnparamTypes
- 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 MethodmethodName
- The name of the Method to returnparamType
- 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
-