Modify a method annotation parameter at runtime

2019-04-09 20:38发布

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条回答
男人必须洒脱
2楼-- · 2019-04-09 21:06

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

查看更多
登录 后发表回答