So let's say I use reflection to find a class'subtypes (I'm using the Google Reflections library).
Set<Class<? extends Parent>> subTypes = reflections.getSubTypesOf(Parent.class);
now I want to create a list for each subtype, by iterating over the set's members, so I want something like this:
try {
for (Class<? extends Parent> cType : subTypes.iterator()) {
Class x = Class.forName(cType.getName());
List<x> list = new ArrayList<x>();
}
} catch(ClassNotFoundException ex){
...
}
However, this doesn't work, and the compiler complains that 'x is an unknown class' on the list definition.
Is there a way to define a list based on the reflected types?
Aucun commentaire:
Enregistrer un commentaire