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?
setAccessibledoes 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.