Java reflection - impact of setAccessible(true)

后端 未结 4 1261
萌比男神i
萌比男神i 2020-11-28 23:43

I\'m using some annotations to dynamically set values of fields in classes. Since I want to do this regardless of whether it\'s public, protected, or private, I am a calling

4条回答
  •  醉酒成梦
    2020-11-29 00:02

    The getDeclaredField method has to return a new object each time, exactly because this object has the mutable accessible flag. So there is no need to reset the flag. You can find the full details in this blog post.

提交回复
热议问题