Change private static final field using Java reflection

前端 未结 12 2318
天涯浪人
天涯浪人 2020-11-21 05:52

I have a class with a private static final field that, unfortunately, I need to change it at run-time.

Using reflection I get this error: java.lan

12条回答
  •  情书的邮戳
    2020-11-21 06:27

    I also integrated it with joor library

    Just use

          Reflect.on(yourObject).set("finalFieldName", finalFieldValue);
    

    Also I fixed an issue with override which the previous solutions seem to miss. However use this very carefully, only when there's no other good solution.

提交回复
热议问题