public class ReflectionUtils
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
private |
ReflectionUtils()
Private constructor that should never be called since this is a static
utility class.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.reflect.Constructor |
findConstructor(java.lang.Class<?> clazz,
java.lang.Class<?>... paramTypes)
Attempt to find a
Constructor on the supplied class with the
supplied parameter types. |
static java.lang.reflect.Field |
findField(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?> type)
Attempt to find a
field on the supplied Class with
the supplied name and/or type. |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... paramTypes)
Attempt to find a
Method on the supplied class with the supplied
name and parameter types. |
static java.lang.Object |
getEnumValue(java.lang.Class<?> clazz,
java.lang.String valueName)
Find and return the specified value from the specified enum class.
|
static java.lang.Object |
getField(java.lang.reflect.Field field,
java.lang.Object target)
Get the field represented by the supplied
field object on
the specified target object. |
static java.lang.Object |
getStaticField(java.lang.reflect.Field field)
Get the field represented by the supplied
field object on
the specified target object. |
static java.lang.Object |
invokeConstructor(java.lang.reflect.Constructor constructor,
java.lang.Object... args)
Invoke the specified
Constructor with the supplied arguments. |
static java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object target,
java.lang.Object... args)
Invoke the specified
Method against the supplied target object
with the supplied arguments. |
static java.lang.Object |
invokeStaticMethod(java.lang.reflect.Method method,
java.lang.Object... args)
Invoke the specified static
Method with the supplied arguments. |
private ReflectionUtils()
public static java.lang.reflect.Method findMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... paramTypes)
Method on the supplied class with the supplied
name and parameter types. Searches all superclasses up to
Object.clazz - The class to introspectname - The name of the methodparamTypes - The parameter types of the method
(may be null to indicate any signature)public static java.lang.reflect.Constructor findConstructor(java.lang.Class<?> clazz,
java.lang.Class<?>... paramTypes)
Constructor on the supplied class with the
supplied parameter types. Searches all superclasses up to
Object.clazz - The class to introspectparamTypes - The parameter types of the method (may be null to indicate any signature)public static java.lang.Object invokeMethod(java.lang.reflect.Method method,
java.lang.Object target,
java.lang.Object... args)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException
Method against the supplied target object
with the supplied arguments. The target object can be null
when invoking a static Method.method - The method to invoketarget - The target object to invoke the method onargs - The invocation arguments (may be null)java.lang.IllegalAccessException - when unable to access the specified method because access modifiers prevent itjava.lang.reflect.InvocationTargetException - when a reflection invocation failspublic static java.lang.Object invokeStaticMethod(java.lang.reflect.Method method,
java.lang.Object... args)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException
Method with the supplied arguments.method - The method to invokeargs - The invocation arguments (may be null)java.lang.IllegalAccessException - when unable to access the specified method because access modifiers prevent itjava.lang.reflect.InvocationTargetException - when a reflection invocation failspublic static java.lang.Object invokeConstructor(java.lang.reflect.Constructor constructor,
java.lang.Object... args)
throws java.lang.reflect.InvocationTargetException,
java.lang.IllegalAccessException,
java.lang.InstantiationException
Constructor with the supplied arguments.constructor - The method to invokeargs - The invocation arguments (may be null)java.lang.IllegalAccessException - when unable to access the specified constructor because access modifiers prevent itjava.lang.reflect.InvocationTargetException - when a reflection invocation failsjava.lang.InstantiationException - when an instantiation failspublic static java.lang.reflect.Field findField(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?> type)
field on the supplied Class with
the supplied name and/or type. Searches all
superclasses up to Object.clazz - The class to introspectname - The name of the field (may be null if type is specified)type - The type of the field (may be null if name is specified)public static java.lang.Object getField(java.lang.reflect.Field field,
java.lang.Object target)
throws java.lang.IllegalAccessException
field object on
the specified target object. In accordance with
Field.get(Object) semantics, the returned value is automatically
wrapped if the underlying field has a primitive type.field - The field to gettarget - The target object from which to get the fieldjava.lang.IllegalAccessException - when unable to access the specified field because access modifiers prevent itpublic static java.lang.Object getStaticField(java.lang.reflect.Field field)
throws java.lang.IllegalAccessException
field object on
the specified target object. In accordance with
Field.get(Object) semantics, the returned value is automatically
wrapped if the underlying field has a primitive type.field - The field to getjava.lang.IllegalAccessException - when unable to access the specified field because access modifiers prevent itpublic static java.lang.Object getEnumValue(java.lang.Class<?> clazz,
java.lang.String valueName)
clazz - The enum class to introspectvalueName - The name of the enum value to get