我注释了这样的任何字段:
@MyAnnotation("annotation")
public String[] values;
我这样做:
for(Field field : AnnotatedClass.getClass.getFields())
if (field.isAnnotationPresent(MyAnnotation.class)){
// but I don't know how to get values String[] array
// I try to cast but inconvertible types
}
感谢您的任何想法和帮助!!
答案 0 :(得分:0)
您可以使用field.getAnnotation()
:
for (Field f : AnnotatedClass.getClass.getFields())
if (field.isAnnotationPresent(MyAnnotation.class)) {
MyAnnotation anno = field.getAnnotation(MyAnnotation.class);
String values = anno.value();
}
}