Java Reflection Interface Get getInterfaces(final Class type)

Here you can find the source of getInterfaces(final Class type)

Description

Returns all interfaces of this class and its super's.

License

Open Source License

Parameter

Parameter Description
type Class to check

Return

List of interfaces

Declaration

public final static List<Class<?>> getInterfaces(final Class<?> type) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**//  w w w  .  ja va  2  s.  c o m
     * Returns all interfaces of this class and its super's. If the class is an interface itself this is also returned.
     *
     * @param type Class to check
     * @return List of interfaces
     */
    public final static List<Class<?>> getInterfaces(final Class<?> type) {

        // get all the interfaces of the class
        List<Class<?>> interfaces = new ArrayList<Class<?>>();
        if (type.isInterface()) {
            interfaces.add(type);
        } else {
            Class<?> loop = type;
            while (!loop.equals(Object.class)) {
                for (Class<?> interfacez : loop.getInterfaces()) {
                    interfaces.add(interfacez);
                }
                loop = loop.getSuperclass();
            }
        }
        return interfaces;
    }
}

Related

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