Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test
- {
- static void setFinalStatic(Field field, Object newValue) throws Exception
- {
- field.setAccessible(true);
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
- field.set(null, newValue);
- }
- public static void main(String args[]) throws Exception
- {
- setFinalStatic(Boolean.class.getField("FALSE"), true);
- System.out.format("Everything is %s", false); // "Everything is true"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement