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-03-16 22:14:41 发布


697

被折叠的 条评论
为什么被折叠?



