Advertisement
sci4me

lol, it works!

Feb 2nd, 2015
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public class Test
  2. {
  3.     static void setFinalStatic(Field field, Object newValue) throws Exception
  4.     {
  5.         field.setAccessible(true);
  6.  
  7.         Field modifiersField = Field.class.getDeclaredField("modifiers");
  8.         modifiersField.setAccessible(true);
  9.         modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
  10.  
  11.         field.set(null, newValue);
  12.     }
  13.  
  14.     public static void main(String args[]) throws Exception
  15.     {
  16.         setFinalStatic(Boolean.class.getField("FALSE"), true);
  17.  
  18.         System.out.format("Everything is %s", false); // "Everything is true"
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement