富国沪深
用反射吧,然后设置setAccessible为true就可以了,如下:public class Test {private String readOnly;
public String getReadOnly() {
return readOnly;
}
public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Test t = new Test();
Field f = t.getClass().getDeclaredField("readOnly");
f.setAccessible(true);
f.set(t, "test");
System.out.println(t.getReadOnly());
}}