jeudi 28 juin 2018

Why getAnnotatedParameterTypes does not see annotations for array argument?

For some reason I don't understand why this code prints true and false, what is special about array that it does not include that annotation here?
It works as expected if you use getParameters instead.

public static void a(@Lel String args) {}
public static void b(@Lel String[] args) {}
public static void main(String[] args) throws Exception {
    System.out.println(Test.class.getDeclaredMethod("a", String.class).getAnnotatedParameterTypes()[0].isAnnotationPresent(Lel.class));
    System.out.println(Test.class.getDeclaredMethod("b", String[].class).getAnnotatedParameterTypes()[0].isAnnotationPresent(Lel.class));
}





Aucun commentaire:

Enregistrer un commentaire