/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces( final Class<?> target, final Class<T> type) { List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces(final Class<?> target, final Class<T> type) { final List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); final Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") final Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
/** * Get all interfaces the extends the type provided. */ public static <T> List<Class<? extends T>> getInterfaces(final Class<?> target, final Class<T> type) { final List<Class<? extends T>> ret = new ArrayList<Class<? extends T>>(); final Collection<Class<?>> interfs = getAllInterfaces(target); for (Class<?> clazz : interfs) { if (containsInterface(clazz, type)) { @SuppressWarnings("unchecked") final Class<? extends T> o = (Class<? extends T>) clazz; ret.add(o); } } return ret; }
@Test public void functional() { // getInterfaces Set<Class<?>> set = getAllInterfaces(C1.class); assertTrue(set.contains(I1.class)); assertTrue(set.contains(I2.class)); assertFalse(set.contains(I3.class)); // containsInterface assertTrue(containsInterface(C1.class, I1.class)); assertTrue(containsInterface(C1.class, I2.class)); assertFalse(containsInterface(C1.class, I3.class)); }