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 contain class objects represent subtypes of foo (foo.class, bla.class, blub.class).

  • list<? extends foo> can contain objects subtypes of foo.

you want second version.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -