public class ReflectionUtil extends Object
| Constructor and Description |
|---|
ReflectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static Field |
getField(Class clazz,
String name)
Get a field from a given class
|
static <T> T |
getFieldValue(Object target,
String name)
Get a field value from a given object
|
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 <T> T |
getStaticFieldValue(Class<?> target,
String name)
Get a field value from a given class
|
static <T> T |
newInstance(String className)
New target Object instance using the given Class name
|
static <T> T |
newInstance(Supplier<Constructor<T>> constructorSupplier,
Object... args)
New target Object instance using the given arguments
|
static void |
setField(Object target,
Field field,
Object value)
Set target Object field to a certain value
|
static void |
setField(Object target,
String fieldName,
Object value)
Set target Object field to a certain value
|
static void |
setProperty(Object target,
String property,
Object parameter)
Invoke setter method with the given parameter
|
static void |
setStaticField(Class<?> target,
String fieldName,
Object value)
Set target Class field to a certain value
|
public static Field getField(Class clazz, String name)
clazz - clazzname - field namepublic static <T> T getFieldValue(Object target, String name)
target - Object whose field is being readname - field namepublic static <T> T getStaticFieldValue(Class<?> target, String name)
target - Class whose field is being readname - field namepublic static void setField(Object target, Field field, Object value)
target - Object whose field is being setfield - Object field to setvalue - the new value for the given fieldpublic static void setField(Object target, String fieldName, Object value)
target - Object whose field is being setfieldName - Object field naem to setvalue - the new value for the given fieldpublic static void setStaticField(Class<?> target, String fieldName, Object value)
target - Class whose field is being setfieldName - Class field name to setvalue - the new value for the given fieldpublic static <T> T newInstance(Supplier<Constructor<T>> constructorSupplier, Object... args)
constructorSupplier - constructor supplierargs - Constructor argumentspublic static <T> T newInstance(String className)
className - class namepublic static Method getSetter(Object target, String property, Class<?> parameterType)
target - target objectproperty - propertyparameterType - setter parameter typepublic static Method getMethod(Object target, String methodName, Class... parameterTypes)
target - target objectmethodName - method nameparameterTypes - method parameter typesCopyright © 2001-2019 Red Hat, Inc. All Rights Reserved.