i was trying to learn reflection and i across the question, why didn't it have a exception??
public class FieldExceptionTest {
private boolean b = true;
public static void main(String[] args) throws Exception{
FieldExceptionTest ft = new FieldExceptionTest();
Class<?> c = ft.getClass();
Field f = c.getDeclaredField("b");
// f.setAccessible(true); //if i don't write this line, it also can run.
f.setBoolean(ft, Boolean.FALSE);
System.out.println(ft.b);
}
}
why did't it throw IllegalAccessException?? By reading other book, i know that An IllegalAccessException may be thrown if an attempt is made to get or set the value of a private or otherwise inaccessible field or to set the value of a final field. But here ,it did't , why?