报错内容:
Exception in thread “main” java.lang.IllegalAccessException: Class Test can not access a member of class xxxx with modifiers “private”
再现情况:
使用反射获取实体类私有字段自定义注解的值。
如何解决:
类属性加上 field.setAccessible(true);
本文介绍了一种在使用反射获取私有字段自定义注解值时遇到的IllegalAccessException异常,并提供了解决方案,即通过设置field.setAccessible(true)来允许访问。
报错内容:
Exception in thread “main” java.lang.IllegalAccessException: Class Test can not access a member of class xxxx with modifiers “private”
再现情况:
使用反射获取实体类私有字段自定义注解的值。
如何解决:
类属性加上 field.setAccessible(true);
1476

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