在Java中使用反射修改私有属性

Integer a = Integer.valueOf(1);
// TODO
Field f = a.getClass().getDeclaredField("value");
f.setAccessible(true);
f.set(a,2);
System.out.println(a.intValue()); // 输出2

 参考链接

https://blog.csdn.net/tabactivity/article/details/50726353

相关文章:

  • 2021-09-28
  • 2021-11-08
  • 2021-10-17
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2019-08-10
相关资源
相似解决方案