public class ReflectionHelpers extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ReflectionHelpers.ClassParameter<V>
Typed parameter used with reflective method calls.
|
static class |
ReflectionHelpers.StringParameter<V>
String parameter used with reflective method calls.
|
| Constructor and Description |
|---|
ReflectionHelpers() |
| Modifier and Type | Method and Description |
|---|---|
static <R> R |
callConstructor(Class<? extends R> clazz,
ReflectionHelpers.ClassParameter<?>... classParameters)
Reflectively call the constructor of an object.
|
static <R> R |
callInstanceMethod(Class<?> cl,
Object instance,
String methodName,
ReflectionHelpers.ClassParameter<?>... classParameters)
Reflectively call an instance method on an object on a specific class.
|
static <R> R |
callInstanceMethod(Object instance,
String methodName,
ReflectionHelpers.ClassParameter<?>... classParameters)
Reflectively call an instance method on an object.
|
static <R> R |
callStaticMethod(Class<?> clazz,
String methodName,
ReflectionHelpers.ClassParameter<?>... classParameters)
Reflectively call a static method on a class.
|
static <R> R |
getField(Object object,
String fieldName)
Reflectively get the value of a field.
|
static <R> R |
getStaticField(Class<?> clazz,
String fieldName)
Reflectively get the value of a static field.
|
static <R> R |
getStaticField(Field field)
Reflectively get the value of a static field.
|
static Class<?> |
loadClass(ClassLoader classLoader,
String fullyQualifiedClassName)
Load a class.
|
static <T> T |
newInstance(Class<T> cl)
Create a new instance of a class
|
static void |
setField(Class<?> type,
Object object,
String fieldName,
Object fieldNewValue)
Reflectively set the value of a field.
|
static void |
setField(Object object,
String fieldName,
Object fieldNewValue)
Reflectively set the value of a field.
|
static void |
setStaticField(Class<?> clazz,
String fieldName,
Object fieldNewValue)
Reflectively set the value of a static field.
|
static void |
setStaticField(Field field,
Object fieldNewValue)
Reflectively set the value of a static field.
|
public static <R> R getField(Object object, String fieldName)
R - The return type.object - Target object.fieldName - The field name.public static void setField(Object object, String fieldName, Object fieldNewValue)
object - Target object.fieldName - The field name.fieldNewValue - New value.public static void setField(Class<?> type, Object object, String fieldName, Object fieldNewValue)
type - Target type.object - Target object.fieldName - The field name.fieldNewValue - New value.public static <R> R getStaticField(Field field)
R - The return type.field - Field object.public static <R> R getStaticField(Class<?> clazz, String fieldName)
R - The return type.clazz - Target class.fieldName - The field name.public static void setStaticField(Field field, Object fieldNewValue)
field - Field object.fieldNewValue - The new value.public static void setStaticField(Class<?> clazz, String fieldName, Object fieldNewValue)
clazz - Target class.fieldName - The field name.fieldNewValue - The new value.public static <R> R callInstanceMethod(Object instance, String methodName, ReflectionHelpers.ClassParameter<?>... classParameters)
R - The return type.instance - Target object.methodName - The method name to call.classParameters - Array of parameter types and values.public static <R> R callInstanceMethod(Class<?> cl, Object instance, String methodName, ReflectionHelpers.ClassParameter<?>... classParameters)
R - The return type.cl - The class.instance - Target object.methodName - The method name to call.classParameters - Array of parameter types and values.public static <R> R callStaticMethod(Class<?> clazz, String methodName, ReflectionHelpers.ClassParameter<?>... classParameters)
R - The return type.clazz - Target class.methodName - The method name to call.classParameters - Array of parameter types and values.public static Class<?> loadClass(ClassLoader classLoader, String fullyQualifiedClassName)
classLoader - The class loader.fullyQualifiedClassName - The fully qualified class name.public static <T> T newInstance(Class<T> cl)
T - The class type.cl - The class object.public static <R> R callConstructor(Class<? extends R> clazz, ReflectionHelpers.ClassParameter<?>... classParameters)
R - The return type.clazz - Target class.classParameters - Array of parameter types and values.Copyright © 2016. All rights reserved.