在运行时修改方法注释参数

问题描述 投票:4回答:1

我找到了这个帖子:How to change annotation value at runtime using reflection?

我正在尝试更改方法注释,但java.lang.reflect.Method不包含任何地图字段,如“注释”或类似“getDeclaredAnnotationMap”的方法

只有private byte[] annotations但我能用这个字节数组做什么?

那么,如何修改方法的注释呢?

编辑: 我创造了:http://pastebin.com/T2rewcwU 但是只编辑这个方法实例,如果取消注释33行代码,则值将重置。

java reflection methods annotations
1个回答
1
投票

我写了一个类qazxsw poi来解决系列要求。

它可以在类/字段/方法实例上添加/删除/更改注释值。

请注意,在添加/删除注释时使用AnnotationUtil来获取根域/方法。

在github上看到它:

ReflectUtil

AnnotationUtil

© www.soinside.com 2019 - 2024. All rights reserved.