Here you can find the source of getSuperClasses(Class> clazz)
Parameter | Description |
---|---|
clazz | the class to start traversal from |
public static List<Class<?>> getSuperClasses(Class<?> clazz)
//package com.java2s; /*-------------------------------------------------------------------------+ | | | Copyright 2005-2011 The ConQAT Project | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | | You may obtain a copy of the License at | | | | http://www.apache.org/licenses/LICENSE-2.0 | | | | Unless required by applicable law or agreed to in writing, software | | distributed under the License is distributed on an "AS IS" BASIS, | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | See the License for the specific language governing permissions and | | limitations under the License. | +-------------------------------------------------------------------------*/ import java.util.ArrayList; import java.util.List; public class Main { /**//w w w . j a v a 2s .com * Get super class list of a class. * * @param clazz * the class to start traversal from * @return a list of super class where the direct super class of the * provided class is the first member of the list. <br> * For {@link Object}, primitives and interfaces this returns an * empty list. <br> * For arrays this returns a list containing only {@link Object}. <br> * For enums this returns a list containing {@link Enum} and * {@link Object} */ public static List<Class<?>> getSuperClasses(Class<?> clazz) { ArrayList<Class<?>> superClasses = new ArrayList<Class<?>>(); findSuperClasses(clazz, superClasses); return superClasses; } /** * Recursively add super classes to a list. * * @param clazz * class to start from * @param superClasses * list to store super classes. */ private static void findSuperClasses(Class<?> clazz, List<Class<?>> superClasses) { Class<?> superClass = clazz.getSuperclass(); if (superClass == null) { return; } superClasses.add(superClass); findSuperClasses(superClass, superClasses); } }