[英]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"我正在尝试更改方法注释,但 java.lang.reflect.Method 不包含任何像“注释”这样的映射字段或像“getDeclaredAnnotationMap”这样的方法
There is only private byte[] annotations
but what can I do with this byte array?只有
private byte[] annotations
但我可以用这个字节数组做什么?
So, how to modify annotation of method?那么,如何修改方法的注解呢?
EDIT:编辑:
I created that: http://pastebin.com/T2rewcwU我创建的: http : //pastebin.com/T2rewcwU
But that only edit this instance of method, if you uncomment 33 line of code then value will reset.但是只编辑这个方法实例,如果你取消注释 33 行代码,那么值将重置。
I wrote a class AnnotationUtil
to resolve the seris requirements.我写了一个类
AnnotationUtil
来解决系列需求。
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.请注意,在添加/删除注释时使用
ReflectUtil
获取根字段/方法。
See it on github:在github上看到它:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.