public class PrivateAccessor extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
construct(Class<?> clazz,
Object... args)
访问任意类的私有构造方法
|
static <T> T |
get(Object ref,
String fieldName)
读取任意类的私有字段
|
static <T> T |
getStatic(Class<?> clazz,
String fieldName)
读取任意类的静态私有字段
|
static <T> T |
invoke(Object ref,
String method,
Object... args)
调用任意类的私有方法
|
static <T> T |
invokeStatic(Class<?> clazz,
String method,
Object... args)
调用任意类的静态私有方法
|
static <T> void |
set(Object ref,
String fieldName,
T value)
修改任意类的私有字段(或常量字段)
|
static <T> void |
setStatic(Class<?> clazz,
String fieldName,
T value)
修改任意类的静态私有字段(或静态常量字段)
|
public static <T> T get(Object ref, String fieldName)
ref - 目标对象fieldName - 目标字段名public static <T> void set(Object ref, String fieldName, T value)
ref - 目标对象fieldName - 目标字段名value - 目标值public static <T> T invoke(Object ref, String method, Object... args)
ref - 目标对象method - 目标方法名args - 方法参数public static <T> T getStatic(Class<?> clazz, String fieldName)
clazz - 目标类型fieldName - 目标字段名public static <T> void setStatic(Class<?> clazz, String fieldName, T value)
clazz - 目标类型fieldName - 目标字段名value - 目标值public static <T> T invokeStatic(Class<?> clazz, String method, Object... args)
clazz - 目标类型method - 目标方法名args - 方法参数Copyright © 2021. All rights reserved.