Modify a method annotation parameter at runtime

£可爱£侵袭症+ 提交于 2019-12-09 13:11:10

问题


I found this thread: How to change annotation value at runtime using reflection?

And I'm trying to change method annotation, but java.lang.reflect.Method does not contain any map-field like "annotations" or method like "getDeclaredAnnotationMap"

There is only private byte[] annotations but what can I do with this byte array?

So, how to modify annotation of method?

EDIT:
I created that: http://pastebin.com/T2rewcwU
But that only edit this instance of method, if you uncomment 33 line of code then value will reset.


回答1:


I wrote a class AnnotationUtil to resolve the seris requirements.

It can add/remove/change annotation value on class/field/method instance.

Note that use ReflectUtil to get root field/method when add/remove annotation.

See it on github:

AnnotationUtil

ReflectUtil



来源:https://stackoverflow.com/questions/27697358/modify-a-method-annotation-parameter-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!