@Test @SuppressWarnings("unchecked") public void shouldReturnAncestors() { class A { } class B extends A { } Iterable<Class<? super B>> ancestors = ReflectionUtils.getAncestors(B.class); assertThat(ancestors).contains(A.class); }
public static <T> Iterable<Class<? super T>> getAncestors(Class<T> klass) { Deque<Class<? super T>> ancestors = new LinkedList<>(); for (Class<?> ancestor = klass; ancestor != Object.class; ancestor = ancestor.getSuperclass()) { @SuppressWarnings("unchecked") final Class<? super T> acestorCasted = (Class<? super T>) ancestor; ancestors.addFirst(acestorCasted); } return ancestors; }
ReflectionUtils { public static <T> Iterable<Class<? super T>> getAncestors(Class<T> klass) { Deque<Class<? super T>> ancestors = new LinkedList<>(); for (Class<?> ancestor = klass; ancestor != Object.class; ancestor = ancestor.getSuperclass()) { @SuppressWarnings("unchecked") final Class<? super T> acestorCasted = (Class<? super T>) ancestor; ancestors.addFirst(acestorCasted); } return ancestors; } }
ReflectionUtils { public static <T> Iterable<Class<? super T>> getAncestors(Class<T> klass) { Deque<Class<? super T>> ancestors = new LinkedList<>(); for (Class<?> ancestor = klass; ancestor != Object.class; ancestor = ancestor.getSuperclass()) { @SuppressWarnings("unchecked") final Class<? super T> acestorCasted = (Class<? super T>) ancestor; ancestors.addFirst(acestorCasted); } return ancestors; } private  ReflectionUtils(); }
ReflectionUtils { public static <T> Iterable<Class<? super T>> getAncestors(Class<T> klass) { Deque<Class<? super T>> ancestors = new LinkedList<>(); for (Class<?> ancestor = klass; ancestor != Object.class; ancestor = ancestor.getSuperclass()) { @SuppressWarnings("unchecked") final Class<? super T> acestorCasted = (Class<? super T>) ancestor; ancestors.addFirst(acestorCasted); } return ancestors; } private  ReflectionUtils(); static Iterable<Class<? super T>> getAncestors(Class<T> klass); static boolean isMethodOverriden(Class<? extends T> klass, Class<T> parentClass, String methodName); static Method findMethod(Class<? extends T> klass, String methodName); }
ReflectionUtils { public static <T> Iterable<Class<? super T>> getAncestors(Class<T> klass) { Deque<Class<? super T>> ancestors = new LinkedList<>(); for (Class<?> ancestor = klass; ancestor != Object.class; ancestor = ancestor.getSuperclass()) { @SuppressWarnings("unchecked") final Class<? super T> acestorCasted = (Class<? super T>) ancestor; ancestors.addFirst(acestorCasted); } return ancestors; } private  ReflectionUtils(); static Iterable<Class<? super T>> getAncestors(Class<T> klass); static boolean isMethodOverriden(Class<? extends T> klass, Class<T> parentClass, String methodName); static Method findMethod(Class<? extends T> klass, String methodName);  }