I am very new to Reflection, and I have a doubt:
public void setAccessible(boolean flag) throws SecurityException
This method has a boolen parameter flag that indicates the new availability of any fields or methods.
For example, if we try to access the private method of a class from outside the class, then we select the method using getDeclaredMethod and set the accessibility to true , so you can call it, for example: method.setAccessible(true);
Now, in what scenario should we use method.setAccessible(false); , for example, it can be used when there is a public method, and we set the accessibility to false. But what is the need? As far as I understand? If there is no use of method.setAccessible(false) , then we can change the method signature as:
public void setAccessible() throws SecurityException
source share