List of everything that implements such class

1

Well I wanted to know why I can not create a class list that implements another class, for example

public List<Class<? implements Classe>> classes; This returns a syntax error ...

But I can create one of classes that extend from another class ...

public List<Class<? extends Classe>> classes; does not return any errors ...

    
asked by anonymous 22.02.2015 / 20:17

1 answer

0

Although the keyword is the same, extends in a generic declaration works for both class and interface. That is, you can instead create a list of everything that implements an interface, just as it creates a list of everything inherited from a class:

interface CommandExecutor { }

class Foo implements CommandExecutor { }
class Bar implements CommandExecutor { }

public List<Class<? extends CommandExecutor>> commandExecutos =
    new ArrayList<Class<? extends CommandExecutor>>();

Example in ideone ( same example with classes ).

    
22.02.2015 / 20:49