podam icon indicating copy to clipboard operation
podam copied to clipboard

Arrays.asList() is implemented AbstractList, is not work to add method

Open kskim opened this issue 11 years ago • 2 comments

public static List<Annotation> getAttributeAnnotations(final Field attribute,
        final Method setter) {

    Annotation[] annotations = (attribute != null ? attribute.getAnnotations() : null);

    List<Annotation> retValue;
    if (annotations != null && annotations.length != 0) {
        retValue = Arrays.asList(annotations);
    } else {
        retValue = new ArrayList<Annotation>();
    }
    for (Annotation annotation : setter.getParameterAnnotations()[0]) {
        retValue.add(annotation);
    }

    return retValue;
}

// this code is not work. for (Annotation annotation : setter.getParameterAnnotations()[0]) { retValue.add(annotation); }

//retValue is AbstractList. then is not work to add method, see this AbstractList.java:148 code

kskim avatar Jul 23 '15 06:07 kskim

It's not java.util.AbstractList, but java.util.Arrays.ArrayList, which is immutable.

daivanov avatar Jul 23 '15 13:07 daivanov

Just try this POJO

public class AnnotatedPojo {

    @PodamStringValue(strValue = "XYZ")
    private String postCode;

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(@PodamStringValue(strValue = "XYZ") String postCode) {
        this.postCode = postCode;
    }
}

daivanov avatar Jul 24 '15 07:07 daivanov