try {
Class clazz = Class.forName(“package.ClassName”);
Object instance = clazz.newInstance();
Field field = clazz.getDeclaredField(“privateFiled”);
field.setAccessible(true);
field.set(instance, true);
Object filed= field.get(instance);
// filed即为获取到的私有属性
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
}
使用反射暴力访问私有属性
最新推荐文章于 2022-07-27 22:04:38 发布