Why the follow line produce a compile error in Java? Or how I can write the correct generics syntax?
Class<? extends Annotation> annotation = annotations[i];
Class<? extends Annotation> anno = javaClass.getAnnotation(annotation);
该方法的签名是:
public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
Eclipse的错误:
Type mismatch: cannot convert from capture#5-of ? extends Annotation to Class<? extends Annotation>
javac的错误:
incompatible types
Class<? extends Annotation> anno = javaClass.getAnnotation(annotation);
^
required: Class<? extends Annotation>
found: CAP#1
where CAP#1 is a fresh type-variable:
CAP#1 extends Annotation from capture of ? extends Annotation