[英]How to get value from as array annotated filed?
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: 您可以field.getAnnotation()
使用field.getAnnotation()
:
for (Field f : AnnotatedClass.getClass.getFields())
if (field.isAnnotationPresent(MyAnnotation.class)) {
MyAnnotation anno = field.getAnnotation(MyAnnotation.class);
String values = anno.value();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.