在运行时修改方法注释参数 [英] Modify a method annotation parameter at runtime
问题描述
我找到了这个帖子:如何更改注释值运行时使用反射?
我正在尝试更改方法注释,但java.lang.reflect.Method不包含任何地图字段,如注释或类似getDeclaredAnnotationMap的方法
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?
编辑:
我创建了: http://pastebin.com/T2rewcwU
但是只编辑这个方法实例,如果取消注释33行代码,则值将重置。
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.
推荐答案
我写了一个类 AnnotationUtil
来解决seris要求。
I wrote a class AnnotationUtil
to resolve the seris requirements.
它可以添加/删除/更改注释v类/字段/方法实例上的alue。
It can add/remove/change annotation value on class/field/method instance.
注意在添加/时使用 ReflectUtil
来获取root字段/方法删除注释。
Note that use ReflectUtil
to get root field/method when add/remove annotation.
在github上看到它:
See it on github:
这篇关于在运行时修改方法注释参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!