Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify a method annotation parameter at runtime

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.

like image 893
GotoFinal Avatar asked Dec 29 '14 23:12

GotoFinal


1 Answers

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

like image 147
Dean Xu Avatar answered Nov 10 '22 00:11

Dean Xu