I tried to modify private final static variable like this:
...try {
Field f =TargetA.class.getDeclaredField("RECV_TIMEOUT");
f.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
f.set(null, 12L);
} catch (Exception e) {
e.printStackTrace();//not reach here!
} ...
class TargetA{
private static final long RECV_TIMEOUT = 180000L;
}
However TargetA.RECV_TIMEOUT
is still 180000L, without any Exception.
I searched the problem in StackOverflow, but couldn’t find solution.
I guess the Java version1.6 has more restriction in reflection which breaks OO rules. Thanks for your advice!