private static <T> void getImplementedInterfaces(Class<? super T> clazz, Set<Class<? super T>> classes) { for ( Class<?> currentInterface : clazz.getInterfaces() ) { @SuppressWarnings("unchecked") //safe since interfaces are super-types Class<? super T> currentInterfaceCasted = (Class<? super T>) currentInterface; classes.add( currentInterfaceCasted ); getImplementedInterfaces( currentInterfaceCasted, classes ); } } }
private static <T> void getImplementedInterfaces(Class<? super T> clazz, Set<Class<? super T>> classes) { for ( Class<?> currentInterface : clazz.getInterfaces() ) { @SuppressWarnings("unchecked") //safe since interfaces are super-types Class<? super T> currentInterfaceCasted = (Class<? super T>) currentInterface; classes.add( currentInterfaceCasted ); getImplementedInterfaces( currentInterfaceCasted, classes ); } } }
/** * Gets all interfaces (and recursively their super-interfaces) which the * given class directly implements. Interfaces implemented by super-classes * are not contained. * * @param clazz the class for which to retrieve the implemented interfaces * @param <T> the type of the class * * @return Set of all interfaces implemented by the class represented by * this hierarchy. The empty list is returned if it does not * implement any interfaces. */ public static <T> Set<Class<? super T>> getDirectlyImplementedInterfaces(Class<T> clazz) { Contracts.assertNotNull( clazz ); Set<Class<? super T>> classes = newHashSet(); getImplementedInterfaces( clazz, classes ); return classes; }
/** * Gets all interfaces (and recursively their super-interfaces) which the * given class directly implements. Interfaces implemented by super-classes * are not contained. * * @param clazz the class for which to retrieve the implemented interfaces * @param <T> the type of the class * * @return Set of all interfaces implemented by the class represented by * this hierarchy. The empty list is returned if it does not * implement any interfaces. */ public static <T> Set<Class<? super T>> getDirectlyImplementedInterfaces(Class<T> clazz) { Contracts.assertNotNull( clazz ); Set<Class<? super T>> classes = newHashSet(); getImplementedInterfaces( clazz, classes ); return classes; }