@@ -0,0 +1,1265 @@
+package com.yxy.chokonu.java.reflection;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.lang.reflect.Modifier;%0A%0Apublic class ChangePrivateFinalStaticField %7B%0A%09%0A%09private static String VAR_STR = %221111%22 ;%0A%09private static final int VAR_INT = 1111 ;%0A%09%0A%09public static void showVar()%7B%0A%09%09System.out.println(%22VAR_STR=%22+VAR_STR);%0A%09%09System.out.println(%22VAR_INT=%22+VAR_INT);%0A%09%7D%0A%0A%09public static void setFinalStatic(Field field, Object newValue) throws Exception %7B%0A%09%09field.setAccessible(true);%0A%0A%09%09Field modifiersField = Field.class.getDeclaredField(%22modifiers%22);%0A%09%09modifiersField.setAccessible(true);%0A%09%09modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);%0A%0A%09%09field.set(null, newValue);%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) throws NoSuchFieldException, SecurityException, Exception %7B%0A%09%09System.out.println(%22Before:%22);%0A%09%09showVar() ;%0A%09%09%0A%09%09setFinalStatic(ChangePrivateFinalStaticField.class.getDeclaredField(%22VAR_STR%22), %222222%22);%0A%09%09%0A%09%09//This value is not changed, because the value of VAR_INT has been changed to constant during compling.%0A%09%09//Therefore, setFinalStatic() only works for non-primitive data type instance.%0A%09%09setFinalStatic(ChangePrivateFinalStaticField.class.getDeclaredField(%22VAR_INT%22), 2222);%0A%09%09%0A%09%09System.out.println(%22After:%22);%0A%09%09showVar() ;%0A%0A%09%7D%0A%0A%7D%0A

add new util to change private static and final fields.