jeudi 2 mai 2019

Why getAnnotation(Parsed.class).field() returning String[]?(It should return String, as it is taking input as String)

I have following code.

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;
}

My question is Parsed(field = "Abc"), here field is taking String as input. But when I am getAnnotation(Parsed.class).field() it is returning String[] instead of String. Why this strange behaviour?

Shouldn't getAnnotation(Parsed.class).field() return String?





Aucun commentaire:

Enregistrer un commentaire