Java Reflection Interface Get getAllInterfaces(Class clazz)

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

Description

Returns all of the interfaces implemented by a class.

License

Open Source License

Parameter

Parameter Description
clazz the class

Return

a list of the interfaces implemented by the class.

Declaration

public static Class[] getAllInterfaces(Class clazz) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

public class Main {
    /**/*www  .  j  a  v a  2s.  c  o  m*/
     * Returns all of the interfaces implemented by a class.
     *
     * @param clazz the class
     * @return a list of the interfaces implemented by the class.
     */
    public static Class[] getAllInterfaces(Class clazz) {
        ArrayList result = new ArrayList();
        getAllInterfaces(clazz, result);
        return (Class[]) result.toArray(new Class[0]);
    }

    /**
     * Returns all of the interfaces inplemented by a class.

     * @param clazz the class
     * @param result     the array to contain the result
     */
    private static void getAllInterfaces(Class clazz, ArrayList result) {
        Class[] interfaces = clazz.getInterfaces();
        for (int i = 0; i < interfaces.length; ++i) {
            if (!result.contains(interfaces[i])) {
                result.add(interfaces[i]);
            }
        }
        Class superClass = clazz.getSuperclass();
        if (superClass != null) {
            getAllInterfaces(superClass, result);
        }
    }
}

Related

  1. addInterfaceName(String name)
  2. equalInterfaces(Object obj1, Object obj2)
  3. getAllClassesAndInterfaces(Class startClass)
  4. getAllInterfaces(Class clazz)
  5. getAllInterfaces(Class clazz)
  6. getAllInterfaces(Class cls)
  7. getAllInterfaces(Class cls)
  8. getAllInterfaces(Class base)