Here you can find the source of getAllSuperClass(Class> clazz, boolean includesObjectClass)
Parameter | Description |
---|---|
clazz | the given object class. |
includesObjectClass | if specifies <b>true</b>, the returned List will be inclued Object class, otherwise, specifies <b>false</b> |
public static List<Class<?>> getAllSuperClass(Class<?> clazz, boolean includesObjectClass)
//package com.java2s; /*/* w w w . j av a 2 s . c o m*/ * Copyright 2007-2009 the original author or authors. * * 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. * * Project: JGentleFramework */ import java.util.ArrayList; import java.util.List; public class Main { /** * Returns all super class of the given class. * * @param clazz * the given object class. * @param includesObjectClass * if specifies <b>true</b>, the returned {@link List} will be * inclued {@link Object} class, otherwise, specifies * <b>false</b> * @return an {@link List} of {@link Class Classes} if they're existed, if * not, returns an empty {@link List}. */ public static List<Class<?>> getAllSuperClass(Class<?> clazz, boolean includesObjectClass) { List<Class<?>> result = new ArrayList<Class<?>>(); Class<?> temp = clazz.getSuperclass(); while (temp != null) { if (includesObjectClass == false) { if (temp == Object.class) { break; } } result.add(temp); temp = temp.getSuperclass(); } return result; } }