What is the reason behind setAccessible method of AccessibleObject class have a boolean parameter?

java, reflection, signature

Solution

Scenario: you removed protection from a private field with `Field.setAccessible(true),` read it and returned the field into original state with `Field.setAccessible(false).`

Problem

I am very new in Reflection and I have a doubt like: ``` public void setAccessible(boolean flag) throws SecurityException ``` This method has a `boolen` parameter flag, which indicates the new accessibility of any fields or methods. For an example if we are try to access a `private` method of a class from outside the class then we fetch the method using `getDeclaredMethod` and set the accessibility as `true`, so it can be invoked, like: `method.setAccessible(true);` Now in which scenario we should use `method.setAccessible(false);` , for an example it can be used when there is a `public` method and we set the accessibility as false. But what is the need of that? Is my understanding clear? If there is no use of `method.setAccessible(false)` then we can change the method signature like: ``` public void setAccessible() throws SecurityException ```

Original source