I’ve found that:
When I’m using Class<?> to declare variable, getAnnotation acts as:
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
, but when I’m using Class to declare variable, getAnnotation acts as:
public Annotation getAnnotation(Annotation annotationClass)
, so I couldn’t compile code, that uses passed annotation class specific methods.
e.g.: I could compile((Class<?>)clazz).getAnnotation(Human.class).age(), but couldn’t compile ((Class)clazz).getAnnotation(Human.class).age(), where clazz is some Class instance, and Human is annotation interface, that have age method.
Your question is very unclear, but I suspect you’re running into a raw type.
JLS — 4.8 Raw Types:
JLS — 4.6 Type Erasure:
So it’s actually that this method:
is erased to this:
That’s why you can call
getAnnotation, but the return type won’t beHuman, it’ll just beAnnotation.