### Question:
ClassUtil { public static <R> R traverse(Class<?> clazz, Function<Class<?>, R> f) { assertNotNull(clazz); { R result = f.apply(clazz); if (result != null) { return result; } } for (Class<?> c : clazz.getInterfaces()) { R result = traverse(c, f); if (result != null) { return result; } } Class<?> superclass = clazz.getSuperclass(); if (superclass == null) { return null; } return traverse(superclass, f); }  static T newInstance(Class<T> clazz); static Constructor<T> getConstructor(Class<T> clazz, Class<?>... parameterTypes); static Method getMethod(Class<T> clazz, String name, Class<?>... parameterTypes); static Method getDeclaredMethod(
      Class<T> clazz, String name, Class<?>... parameterTypes); static Field getDeclaredField(Class<T> clazz, String name); static String getPackageName(String binaryName); static List<String> getEnclosingNames(String binaryName); static String getSimpleName(String binaryName); static Class<?> toBoxedPrimitiveTypeIfPossible(Class<?> clazz); static R traverse(Class<?> clazz, Function<Class<?>, R> f);  }### Answer:
@Test public void testTraverse() { List<Class<?>> list = new ArrayList<>(); ClassUtil.traverse( Ccc.class, c -> { list.add(c); return null; }); assertEquals(8, list.size()); assertEquals(Ccc.class, list.get(0)); assertEquals(ICcc.class, list.get(1)); assertEquals(Bbb.class, list.get(2)); assertEquals(IBbb.class, list.get(3)); assertEquals(IAaa.class, list.get(4)); assertEquals(Aaa.class, list.get(5)); assertEquals(IAaa.class, list.get(6)); assertEquals(Object.class, list.get(7)); }