public final class ReflectionUtils extends Object
ReflectionUtils - Reflection utilities holder.| Modifier and Type | Field and Description |
|---|---|
static String |
GETTER_PREFIX |
static String |
SETTER_PREFIX |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getFieldValue(Object target,
String fieldName)
Get target object field value
|
static Method |
getGetter(Object target,
String property)
Get getter method
|
static Method |
getMethod(Class targetClass,
String methodName,
Class... parameterTypes) |
static Method |
getMethod(Object target,
String methodName,
Class... parameterTypes)
Get target method
|
static Method |
getSetter(Object target,
String property,
Class<?> parameterType)
Get setter method
|
static boolean |
hasMethod(Class<?> targetClass,
String methodName,
Class... parameterTypes)
Check if target class has the given method
|
static <T> T |
invoke(Object target,
Method method,
Object... parameters)
Invoke target method
|
static <T> T |
invokeGetter(Object target,
String property)
Invoke getter method with the given parameter
|
static void |
invokeSetter(Object target,
String property,
boolean parameter)
Invoke setter method with the given parameter
|
static void |
invokeSetter(Object target,
String property,
int parameter)
Invoke setter method with the given parameter
|
static void |
invokeSetter(Object target,
String property,
Object parameter)
Invoke setter method with the given parameter
|
static <T> T |
newInstance(String className)
Instantiate object
|
static void |
setFieldValue(Object target,
String fieldName,
Object value)
Set target object field value
|
public static final String GETTER_PREFIX
public static final String SETTER_PREFIX
public static <T> T newInstance(String className)
T - field typeclassName - Class for object to instantiatepublic static <T> T getFieldValue(Object target, String fieldName)
T - field typetarget - target objectfieldName - field namepublic static void setFieldValue(Object target, String fieldName, Object value)
target - target objectfieldName - field namevalue - field valuepublic static Method getMethod(Object target, String methodName, Class... parameterTypes)
target - target objectmethodName - method nameparameterTypes - method parameter typespublic static Method getMethod(Class targetClass, String methodName, Class... parameterTypes) throws NoSuchMethodException
NoSuchMethodExceptionpublic static boolean hasMethod(Class<?> targetClass, String methodName, Class... parameterTypes)
targetClass - target classmethodName - method nameparameterTypes - method parameter typespublic static Method getSetter(Object target, String property, Class<?> parameterType)
target - target objectproperty - propertyparameterType - setter parameter typepublic static Method getGetter(Object target, String property)
target - target objectproperty - propertypublic static <T> T invoke(Object target, Method method, Object... parameters)
method - method to invokeparameters - method parameterspublic static <T> T invokeGetter(Object target, String property)
target - target objectproperty - propertypublic static void invokeSetter(Object target, String property, Object parameter)
target - target objectproperty - propertyparameter - setter parameterpublic static void invokeSetter(Object target, String property, boolean parameter)
target - target objectproperty - propertyparameter - setter parameterCopyright © 2018. All rights reserved.