package com.logicbig.example.field;
import java.lang.reflect.Field;
public class CanAccessExample {
private static class Test {
private int number;
}
public static void main(String... args) throws NoSuchFieldException {
Field f = Test.class.getDeclaredField("number");
Test testInstance = new Test();
boolean b = f.canAccess(testInstance);
System.out.println(b);
if(!b){
f.setAccessible(true);
System.out.println(f.canAccess(testInstance));
}
}
}