vendredi 10 avril 2020

Change static final field in java 12+

This question is related to Change private static final field using Java reflection. There, it was asked, how to change a private static final variable.

However, these solutions do not work in Java 12+ as you cannot access private variables of java.lang.reflect.Field using Reflection.

When you try to do it despite that, you will end up with a stack trace like:

Exception java.lang.NoSuchFieldException: modifiers
      at Class.getDeclaredField (Class.java:2412)
      at <your call of Field.class.getDeclaredField("modifiers").setAccessible(true)>

Is there any way to change such a constant in those versions?

I could imagine that this would be possible using JNI/JNA.





Aucun commentaire:

Enregistrer un commentaire