深度优先
public class ClassPrint {
private static void printSupers(Class<?> clazz) {
String name = clazz.getCanonicalName();
System.out.println(name);
if(name.equals("java.lang.Object")) return;
if(!clazz.isInterface()) {
Class<?> superClazz = clazz.getSuperclass();
printSupers(superClazz);
}
Class<?>[] superInfArr=clazz.getInterfaces();
for(Class<?> superInf:superInfArr) {
printSupers(superInf);
}
}
public static void printSupers(Object obj) {
printSupers(obj.getClass());
}
}