public final class InjectionUtil extends Object
Utility class for performing a variety of operations through reflection. This functionality should be used sparingly as frequent calls can cause performance issues.
| Modifier and Type | Class and Description |
|---|---|
static class |
InjectionUtil.GenericType<T> |
| Modifier and Type | Field and Description |
|---|---|
static String |
CALL_CONSTRUCTOR_METHOD |
static String |
CALL_METHOD_METHOD |
static String |
GET_FIELD_METHOD |
static String |
SET_FIELD_METHOD |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
callConstructor(Class<T> targetClass,
Class[] argClasses,
Object[] args)
Instantiates a class by calling the constructor.
|
static <T> T |
callConstructor(InjectionUtil.GenericType<T> targetClass,
Class[] argClasses,
Object[] args) |
static <T> T |
callMethod(Class<T> retClass,
Class<?> targetClass,
Object target,
String method,
Class[] argClasses,
Object[] args)
Calls a method with the provided arguments as parameters.
|
static <T> T |
callMethod(InjectionUtil.GenericType<T> retClass,
Class<?> targetClass,
Object target,
String method,
Class[] argClasses,
Object[] args) |
static <T> T |
getField(Class<T> returnType,
Class<?> targetClass,
Object target,
String field)
Returns the value of a field.
|
static <T> T |
getField(InjectionUtil.GenericType<T> returnType,
Class<?> targetClass,
Object target,
String field) |
static void |
setField(Class<?> targetClass,
Object target,
String field,
Object value)
Updates field with the given value.
|
public static final String GET_FIELD_METHOD
public static final String SET_FIELD_METHOD
public static final String CALL_METHOD_METHOD
public static final String CALL_CONSTRUCTOR_METHOD
public static <T> T getField(Class<T> returnType, Class<?> targetClass, Object target, String field)
Returns the value of a field.
T - type parameterreturnType - type of the fieldtargetClass - class represented by the target parametertarget - object containing the fieldfield - name of the fieldpublic static <T> T getField(InjectionUtil.GenericType<T> returnType, Class<?> targetClass, Object target, String field)
public static void setField(Class<?> targetClass, Object target, String field, Object value)
Updates field with the given value.
targetClass - class representing the object containing the field.target - object containing the field to updatefield - name of the fieldvalue - object to update the field topublic static <T> T callMethod(Class<T> retClass, Class<?> targetClass, Object target, String method, Class[] argClasses, Object[] args)
Calls a method with the provided arguments as parameters.
T - relating type parameterretClass - the method return valuetargetClass - the instance classtarget - the instance containing the methodmethod - the method nameargClasses - types of the method argumentsargs - method arguments used during invocationpublic static <T> T callMethod(InjectionUtil.GenericType<T> retClass, Class<?> targetClass, Object target, String method, Class[] argClasses, Object[] args)
public static <T> T callConstructor(Class<T> targetClass, Class[] argClasses, Object[] args)
Instantiates a class by calling the constructor.
T - relating type parametertargetClass - instance type to constructargClasses - argument types accepted by the constructorargs - constructor argument valuespublic static <T> T callConstructor(InjectionUtil.GenericType<T> targetClass, Class[] argClasses, Object[] args)
Copyright © 2020. All Rights Reserved.