Java Reflection Super Class getAllSuperclasses(Class cls)

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

Description

Gets a List of superclasses for the given class.

License

Open Source License

Parameter

Parameter Description
cls the class to look up, may be <code>null</code>

Return

the List of superclasses in order going up from this one null if null input

Declaration

public static List getAllSuperclasses(Class cls) 

Method Source Code

//package com.java2s;
/*// w ww.jav  a2 s.co  m
 * Copyright (c) 2007-2016 AREasy Runtime
 *
 * This library, AREasy Runtime and API for BMC Remedy AR System, is free software ("Licensed Software");
 * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT,
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 */

import java.util.*;

public class Main {
    /**
     * <p>Gets a <code>List</code> of superclasses for the given class.</p>
     *
     * @param cls the class to look up, may be <code>null</code>
     * @return the <code>List</code> of superclasses in order going up from this one
     *         <code>null</code> if null input
     */
    public static List getAllSuperclasses(Class cls) {
        if (cls == null)
            return null;

        List classes = new ArrayList();
        Class superclass = cls.getSuperclass();

        while (superclass != null) {
            classes.add(superclass);
            superclass = superclass.getSuperclass();
        }

        return classes;
    }
}

Related

  1. findSuperTypes(Class cls, Class endBefore)
  2. getAllSuperClass(Class clazz, boolean includesObjectClass)
  3. getAllSuperclasses(Class cls)
  4. getAllSuperClasses(Class clazz)
  5. getAllSuperclasses(Class clazz)
  6. getAllSuperClasses(Class clz)
  7. getAllSuperTypeNames(Class aClass)