如何在Java中使用Reflection获得注释的值 [英] How to get the value of annotation using Reflection in Java
本文介绍了如何在Java中使用Reflection获得注释的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Java Reflection
获得批注的值?
How can I get the value of the annotation using Java Reflection
?
这是带注释的方法:
@JsonView( { View.class } )
public Element getElement()
{
return element;
}
推荐答案
这里有一些获取注释的方法,
Here the some way to get annotation,
Class<?> cls = Class.forName(name);
cls.getDeclaredAnnotations(); // get all annotation
(cls.getDeclaredMethods()[0]).getAnnotations(); //get annotation of a method
Annotation ety = cls.getAnnotation(Annotation.class); // get annotation of particular annotation class
这篇关于如何在Java中使用Reflection获得注释的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文