Java Reflection Interface Get getInterfaces(Class clazz)

Here you can find the source of getInterfaces(Class clazz)

Description

Gets a List of all interfaces implemented by the given class and its superclasses.

License

Open Source License

Parameter

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

Return

the List of interfaces in order, null if null input

Declaration

public static List<Class<?>> getInterfaces(Class<?> clazz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  w w w. ja  va2s.  com*/
     * <p>
     * Gets a <code>List</code> of all interfaces implemented by the given class
     * and its superclasses.
     * </p>
     * <p/>
     * <p>
     * The order is determined by looking through each interface in turn as
     * declared in the source file and following its hierarchy up. Then each
     * superclass is considered in the same way. Later duplicates are ignored,
     * so the order is maintained.
     * </p>
     *
     * @param clazz the class to look up, may be <code>null</code>
     * @return the <code>List</code> of interfaces in order, <code>null</code>
     *         if null input
     */
    public static List<Class<?>> getInterfaces(Class<?> clazz) {
        if (clazz == null)
            return new ArrayList<Class<?>>(0);
        List<Class<?>> list = new ArrayList<Class<?>>();
        while (clazz != null) {
            Class<?>[] interfaces = clazz.getInterfaces();
            for (Class<?> interface1 : interfaces) {
                if (list.contains(interface1) == false)
                    list.add(interface1);
                List<Class<?>> superInterfaces = getInterfaces(interface1);
                for (Class<?> intface : superInterfaces) {
                    if (list.contains(intface) == false)
                        list.add(intface);
                }
            }
            clazz = clazz.getSuperclass();
        }
        return list;
    }
}

Related

  1. getInterfaceInstance(Class interfaceType)
  2. getInterfaceNames(Class c)
  3. getInterfaces(Class clazz)
  4. getInterfaces(Class c)
  5. getInterfaces(Class clazz)
  6. getInterfaces(final Class type)
  7. getInterfaces(Object owner, String[] interfaceStrings)
  8. getInterfacesForClass(Class type)
  9. getInterfacesList(Class clazz)