I want to do something like this:
List animals = new ArrayList();
for( Class c: list_of_all_classes_available_to_my_app() )
i
I use org.reflections:
Reflections reflections = new Reflections("com.mycompany");
Set> classes = reflections.getSubTypesOf(MyInterface.class);
Another example:
public static void main(String[] args) throws IllegalAccessException, InstantiationException {
Reflections reflections = new Reflections("java.util");
Set> classes = reflections.getSubTypesOf(java.util.List.class);
for (Class extends List> aClass : classes) {
System.out.println(aClass.getName());
if(aClass == ArrayList.class) {
List list = aClass.newInstance();
list.add("test");
System.out.println(list.getClass().getName() + ": " + list.size());
}
}
}