Here you can find the source of getTypeHierarchy(Class> cls)
public static Class<?>[] getTypeHierarchy(Class<?> cls)
//package com.java2s; import java.util.ArrayList; public class Main { public static final Class<Object> CLS_Object = Object.class; public static Class<?>[] getTypeHierarchy(Class<?> cls) { ArrayList<Class<?>> result = getTypeHierarchy(cls, new ArrayList<>()); return result.toArray(new Class<?>[result.size()]); }//from w ww .j a v a2 s. c o m private static ArrayList<Class<?>> getTypeHierarchy(Class<?> cls, ArrayList<Class<?>> result) { result.add(cls); if (cls == CLS_Object) return result; return getTypeHierarchy(cls.getSuperclass(), result); } }