As mentioned here:
"accessibility is a static property that can be determined at compile time; it depends only on types and declaration modifiers."
In this case, what does java.lang.reflect.Field.setAccessible(boolean) function really do in runtime?
setAccessible does not alter the accessibility level of a member. It only allows a certain member to be accessed through reflection alone. This doesn't explicitly break the rules of accessibility, since your code doesn't really access the member: it invokes a Reflection method that internally does some magic, accessing the member on your behalf.
With this in mind there is also a crucial point to note: Java also has a very powerful and unpenetrable security system that can deny the usage of reflection to foreign code. Whenever needed, this mechanism can be used to truly prevent access to private members.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With