mariusz12 mariusz12 - 5 months ago 11
Java Question

Finding class extended Class and implement Interface

I try to use google reflections to finding class which extended abstract class like A and implement interface I. I looked in API but with no result.
My code so far:

Reflections reflections = new Reflections("com.my.company");
Set<Class<? extends A>> subTypes = reflections.getSubTypesOf(A.class);
subTypes.forEach(clazz->{
System.out.println(clazz.getSimpleName());
});


Can any one suggest how I can add next conditions?

Answer

I suppose (did not test), this will filter out the right interfaces in the forEach loop:

for(Class face : clazz.getInterfaces())  {
    if( face.isAssignableFrom(I))  ... do sth ...;
}

I is the I.class of the interface you are looking for.