public final class TestReflectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static Object |
invokePrivateMethod(Object target,
String methodName,
Object... args) |
static void |
setInternalField(Object target,
String fieldName,
Object value)
Set the value of the field of an object.
|
public static void setInternalField(Object target, String fieldName, Object value) throws IllegalAccessException, NoSuchFieldException
target - The target object to set the field value of.fieldName - The name of the field to set the value of.value - The value to set into the object field.IllegalArgumentException - If target object is null.IllegalAccessException - If unable to set the field value of the target object.NoSuchFieldException - If no field found for fieldName.public static Object invokePrivateMethod(Object target, String methodName, Object... args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException
target - The target object to invoke method of.methodName - The name of the method to invoke.args - The arguments of the method to be invoked.IllegalArgumentException - If target object is null.IllegalAccessException - If access to method is illegal.NoSuchMethodException - If no method can be found for name.InvocationTargetException - If the method throws an exception.Copyright © 2017. All rights reserved.