I have few classes in a package, that all implement the same interface. I'd like to get all these classes dynamically, to execute a method. Is that possible in java? If not, how can i do something similar. Should i use reflection?
Thanks
I have few classes in a package, that all implement the same interface. I'd like to get all these classes dynamically, to execute a method. Is that possible in java? If not, how can i do something similar. Should i use reflection?
Thanks
You can use extcos library. https://sourceforge.net/projects/extcos/ For more details, you can refer the mentioned link
Set<Class<? extends MyInterface>> classes = new HashSet<Class<? extends MyInterface>>();
ComponentScanner scanner = new ComponentScanner();
scanner.getClasses(new ComponentQuery() {
protected void query() {
select().
from("my.package1").
andStore(thoseImplementing(MyInterface.class).into(classes)).
returning(none());
}
});