Java Class Hierarchy Get getClassHierarchy(Object obj, Class ignoreClass)

Here you can find the source of getClassHierarchy(Object obj, Class ignoreClass)

Description

Gets the class hierarchy

License

Open Source License

Return

List>

Declaration

public static List<Class<?>> getClassHierarchy(Object obj, Class<?> ignoreClass) 

Method Source Code

//package com.java2s;
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

import java.util.ArrayList;
import java.util.List;

public class Main {
    /** Gets the class hierarchy 
     * /*from   w w w. ja  va 2s .  com*/
     * @return List<Class<?>>
     * 
     * */
    public static List<Class<?>> getClassHierarchy(Object obj, Class<?> ignoreClass) {
        List<Class<?>> ret = new ArrayList<Class<?>>();

        if (null != obj) {
            Class<?> clazz = obj.getClass();

            while (null != clazz && (ignoreClass != clazz)) {
                ret.add(0, clazz);
                clazz = clazz.getSuperclass();
            }
        }
        return ret;
    }
}

Related

  1. getClassHierarchy(Class beanClass)
  2. getClassHierarchy(Class type)
  3. getDistance(Class a, Class b)
  4. getDistanceToInterface(Class to, Class from)
  5. getTypeHierarchy(Class cls)