java 如何在运行时使用反射更改注释值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12274234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change annotation value at runtime using reflection?
提问by Chetan Shirke
Below is the annotation.
下面是注释。
@Before(value="execution(* class.method(**)")
Can i change the value of single value annotation using java reflection?
我可以使用 Java 反射更改单值注释的值吗?
Please suggest.
请建议。
回答by alterfox
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.
此外,注释的保留策略必须是runtime,为此。
The link in the comment to your question leads to a post that lookslike 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 proxyclass to your class.
评论中指向您的问题的链接指向的帖子看起来像您正在询问的内容,但不同之处在于它是关于 JPA/Hibernate 注释的,其中在运行时您会获得类的代理类。