【发布时间】:2019-05-02 11:07:54
【问题描述】:
我有以下代码。
import com.univocity.parsers.annotations.Parsed;
import org.apache.commons.lang3.reflect.FieldUtils;
import java.lang.reflect.Field;
public class MyClass {
public static void main(String args[]) {
try{
for (Field field : FieldUtils.getAllFieldsList(SpendsInputBean.class)) {
String[] headerName = field.getAnnotation(Parsed.class).field();
// ^
// |____________(Shouldn't this be String)
.
.
.
}
}catch(Exception ex){
System.out.println(ex);
}
}
}
class X {
@Parsed(field = "Abc")
private String abc;
}
我的问题是Parsed(field = "Abc"),这里的字段以String 作为输入。但是当我是getAnnotation(Parsed.class).field() 时,它会返回String[] 而不是String。为什么会出现这种奇怪的行为?
不应该getAnnotation(Parsed.class).field()返回String吗?
【问题讨论】:
-
你用的是什么版本的univocity?
-
@rghome 我使用的是 2.5.3
标签: java reflection annotations field univocity