java 代码如何获取一个字段上的注解呢?
下文笔者讲述使用java代码获取类字段上的注解的方法分享,如下所示
打印所有字段上的注解
实现思路: 使用反射中的getDeclareAnnotations() 方法即可获取字段上的注解例:
打印所有字段上的注解
for(Field field : class.getDeclaredFields()){ Class type = field.getType(); String name = field.getName(); Annotation[] annotations = field.getDeclaredAnnotations(); }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。