java - List of Class<? extends Foo> incompatible types -
i'm working on piece of code:
list<class<? extends foo>> models = new arraylist<>(); if (bar == 0) models = getrandomblas(); // returns list<bla> else models = getrandomblubs(); // returns list<blub> with:
public class bla extends foo { ... } public class blub extneds foo { ... } but i'm getting incompatible types: found: 'java.util.list<bla>', required: 'java.util.list<java.lang.class<? extends foo>'
has got idea? knowledge, how ? extends should work...
you're right. how ? extends works, list wants class objects.
list<class<? extends foo>>can containclassobjects represent subtypes offoo(foo.class,bla.class,blub.class).list<? extends foo>can contain objects subtypes offoo.
you want second version.
Comments
Post a Comment