如何在运行时使用反射更改注释值? [英] How to change annotation value at runtime using reflection?

查看:32
本文介绍了如何在运行时使用反射更改注释值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是注释.

@Before(value="execution(* class.method(**)")

我可以使用java反射改变单值注解的值吗?

Can i change the value of single value annotation using java reflection?

请提出建议.

推荐答案

可以在此处.但是要小心使用这种方法,其中还描述了一些注意事项.

The description of what you are looking for can be found here. But be wary about using such approach, some of the caveats of it are also described.

此外,注释的保留策略必须是运行时,为此.

Also, the retention policy of the annotation has to be runtime, for this.

评论中指向您的问题的链接指向的帖子看起来就像您正在询问的内容,但不同之处在于它是关于运行时的 JPA/Hibernate 注释你会得到一个代理类到你的类.

The link in the comment to your question leads to a post that looks like something you are asking about, but the difference is that it is about a JPA/Hibernate annotation where in the run-time you get a proxy class to your class.

这篇关于如何在运行时使用反射更改注释值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆