mercredi 15 juillet 2015

incompatible types error when using generics and reflection

Let: B extends A;

Can somebody tell me why this code:

List<Class<? extends A>> l = Arrays.asList(B.class);

Throws me the following error when trying to compile:

error: incompatible types: List<Class<B>> cannot be converted to List<Class<? extends A>>

while this code:

ArrayList<Class<? extends A>> l = new ArrayList<Class<? extends A>>();
l.add(B.class);

works perfectly fine?





Aucun commentaire:

Enregistrer un commentaire