Keeping in mind the limitations mentioned in the other answers, you can also use openpojo's PojoClassFactory
(available on Maven) in the following manner:
for(PojoClass pojoClass : PojoClassFactory.enumerateClassesByExtendingType(packageRoot, Superclass.class, null)) {
System.out.println(pojoClass.getClazz());
}
Where packageRoot
is the root String of the packages you wish to search in (e.g. "com.mycompany"
or even just "com"
), and Superclass
is your supertype (this works on interfaces as well).