File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
src/main/java/me/mrnavastar/r Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 66
77public class R {
88
9+ private static boolean oldJavaCompat = false ;
10+ static {
11+ try {
12+ Field .class .getDeclaredField ("modifiers" );
13+ oldJavaCompat = true ;
14+ } catch (NoSuchFieldException ignore ) {}
15+ }
16+
917 private final Object instance ;
1018 private final Class <?> clazz ;
1119
@@ -88,7 +96,12 @@ public <T> T get(String name, Class<T> type) {
8896 */
8997 public R set (String name , Object value ) {
9098 try {
91- findField (name , clazz ).set (instance , value );
99+ Field toSet = findField (name , clazz );
100+ if (oldJavaCompat ) {
101+ Field modifiersField = findField ("modifiers" , toSet .getClass ());
102+ modifiersField .setInt (toSet , toSet .getModifiers () & ~java .lang .reflect .Modifier .FINAL );
103+ }
104+ toSet .set (instance , value );
92105 } catch (NoSuchFieldException | IllegalAccessException e ) {
93106 throw new RuntimeException (e );
94107 }
@@ -137,4 +150,4 @@ public Class<?>[] generics() {
137150 }
138151 return new Class []{};
139152 }
140- }
153+ }
You can’t perform that action at this time.
0 commit comments