Class ReflectionUtil
java.lang.Object
org.apache.shardingsphere.data.pipeline.core.util.ReflectionUtil
Reflection utils.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldGet field from class.static <T> TgetFieldValue(Object target, String fieldName, Class<T> valueClass) Get field value from instance target object.static <T> TgetStaticFieldValue(Class<?> targetClass, String fieldName, Class<T> valueClass) Get static field value.static ObjectinvokeMethod(Object target, String methodName, Class<?>[] parameterTypes, Object[] parameterValues) Invoke method.static voidsetFieldValue(Object target, String fieldName, Object value) Set value into target object field.
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
setFieldValue
public static void setFieldValue(Object target, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException Set value into target object field.- Parameters:
target- target objectfieldName- field namevalue- new value- Throws:
NoSuchFieldException- no such field exceptionIllegalAccessException- illegal access exception
-
getFieldValue
public static <T> T getFieldValue(Object target, String fieldName, Class<T> valueClass) throws NoSuchFieldException, IllegalAccessException Get field value from instance target object.- Type Parameters:
T- expected value class- Parameters:
target- target objectfieldName- field namevalueClass- expected value class- Returns:
- target filed value
- Throws:
NoSuchFieldException- no such field exceptionIllegalAccessException- illegal access exception
-
getStaticFieldValue
public static <T> T getStaticFieldValue(Class<?> targetClass, String fieldName, Class<T> valueClass) throws NoSuchFieldException, IllegalAccessException Get static field value.- Type Parameters:
T- expected value class- Parameters:
targetClass- target classfieldName- field namevalueClass- expected value class- Returns:
- target filed value
- Throws:
NoSuchFieldException- no such field exceptionIllegalAccessException- illegal access exception
-
getField
public static Field getField(Class<?> targetClass, String fieldName, boolean isDeclared) throws NoSuchFieldException Get field from class.- Parameters:
targetClass- target classfieldName- field nameisDeclared- is declared- Returns:
Field- Throws:
NoSuchFieldException- no such field exception
-
invokeMethod
public static Object invokeMethod(Object target, String methodName, Class<?>[] parameterTypes, Object[] parameterValues) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException Invoke method.- Parameters:
target- target objectmethodName- method nameparameterTypes- parameter typesparameterValues- parameter values- Returns:
- invoke method result.
- Throws:
NoSuchMethodException- no such field exceptionInvocationTargetException- invocation target exceptionIllegalAccessException- illegal access exception
-