Get Super Interfaces : Interface « Reflection « Java

Get Super Interfaces

 * The contents of this file are subject to the Sapient Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is The Carbon Component Framework.
 * The Initial Developer of the Original Code is Sapient Corporation
 * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

 * Copyright 2003 Sapient
 * @since carbon 2.0
 * @author Greg Hinkle, March 2003
 * @version $Revision: 1.5 $($Author: dvoet $ / $Date: 2003/05/05 21:21:23 $)
public class ClassUtil {

     * Retrieves all interfaces implemented by a specified interface
     * including all recursively extended interfaces and the classes supplied
     * int the parameter.
     * @param childInterfaces a set of interfaces
     * @return Class[] an array of interfaces that includes those specifed
     * in childInterfaces plus all of those interfaces' super interfaces
    public static Class[] getSuperInterfaces(Class[] childInterfaces) {

        List allInterfaces = new ArrayList();

        for (int i = 0; i < childInterfaces.length; i++) {

        return (Class[]) allInterfaces.toArray(new Class[allInterfaces.size()]);

     * Builds an <b>unordered</b> set of all interface and object classes that
     * are generalizations of the provided class.
     * @param classObject the class to find generalization of.
     * @return a Set of class objects.
    public static Set getGeneralizations(Class classObject) {
        Set generalizations = new HashSet();


        Class superClass = classObject.getSuperclass();
        if (superClass != null) {

        Class[] superInterfaces = classObject.getInterfaces();
        for (int i = 0; i < superInterfaces.length; i++) {
            Class superInterface = superInterfaces[i];

        return generalizations;



Related examples in the same category

1.Class Reflection: is it an interfaceClass Reflection: is it an interface
2.Class Reflection: implemented interfaces
3.Determining If a Class Object Represents a Class or Interface
4.The superclass of interfaces is always null
5.Listing the Interfaces That a Class Implements
6.The interfaces for a primitive type is an empty array
7.Listing the Interfaces That an Interface Extends
8.Returns true if type is implementing Map
9.Search over classpath retrieving classes that implement a certain interface
10.Returns true if a class implements Serializable and false otherwise.