Java Class Hierarchy Get getTypeHierarchy(Class cls)

Here you can find the source of getTypeHierarchy(Class cls)

Description

get Type Hierarchy

License

Open Source License

Declaration

public static Class<?>[] getTypeHierarchy(Class<?> cls) 

Method Source Code

//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);
    }
}

Related

  1. getClassHierarchy(Class beanClass)
  2. getClassHierarchy(Class type)
  3. getClassHierarchy(Object obj, Class ignoreClass)
  4. getDistance(Class a, Class b)
  5. getDistanceToInterface(Class to, Class from)