Change the method annotation parameter at run time

I found this topic: How to change the value of annotation at runtime using reflection?

And I'm trying to change the annotation of a method, but java.lang.reflect.Method does not contain any map field, for example, an "annotation" or a method like "getDeclaredAnnotationMap"

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

So how to change method annotation?

EDIT:
I created this: http://pastebin.com/T2rewcwU
But this only edits this instance of the method, if you uncomment 33 lines of code, then the value will be reset.

+4
source share
1 answer

I wrote a class AnnotationUtilto solve the series requirements.

It can add / remove / change the annotation value in an instance of a class / field / method.

Note that use ReflectUtilto get the root field / method when adding / removing annotation.

Take a look at github:

Annotation util

ReflectUtil

+1
source

Source: https://habr.com/ru/post/1569356/


All Articles