Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of Classes implementing an Interface

Is there a way to implement something like

    List<Class<? implements MyInterface>> ClassList = new ArrayList<Class<? implements MyInterface>>(); 

my goal is to create a hashmap from that list, where the keys are the toString methods of the class (defined in MyInterface) and the values are the classes itself. The toString method of every object of this class returns the same result. This way I could create Instances of the classes using the map by searching the right strings.

thank you for trying to help, greetings

like image 779
Jones Avatar asked Dec 12 '12 11:12

Jones


1 Answers

List<Class<? implements MyInterface>> ClassList = new ArrayList<Class<? implements MyInterface>>(); 

should be

List<Class<? extends MyInterface>> ClassList = new ArrayList<Class<? extends MyInterface>>(); 

there is no implements keyword in the world of generics. if you want a type parameter that implements an interface , use the extends keyword to represent it.

like image 119
PermGenError Avatar answered Nov 01 '22 15:11

PermGenError