I annotate any field like this:
@MyAnnotation("annotation")
public String[] values;
and I make so:
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
}
Thanks for any ideas and help!!
You can use field.getAnnotation()
for this:
for (Field f : AnnotatedClass.getClass.getFields())
if (field.isAnnotationPresent(MyAnnotation.class)) {
MyAnnotation anno = field.getAnnotation(MyAnnotation.class);
String values = anno.value();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.