Java Reflection Interface Get getInterfaces(Class c)

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

Description

get Interfaces

License

Apache License

Declaration

public static Class<?>[] getInterfaces(Class<?> c) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static Class<?>[] getInterfaces(Class<?> c) {
        List<Class<?>> result = new ArrayList<>();
        if (c.isInterface()) {
            result.add(c);//www .  java 2s .c o  m
        } else {
            do {
                addInterfaces(c, result);
                c = c.getSuperclass();
            } while (c != null);
        }
        for (int i = 0; i < result.size(); ++i) {
            addInterfaces(result.get(i), result);
        }
        return result.toArray(new Class<?>[result.size()]);
    }

    private static void addInterfaces(Class<?> c, List<Class<?>> list) {
        for (Class<?> intf : c.getInterfaces()) {
            if (!list.contains(intf)) {
                list.add(intf);
            }
        }
    }
}

Related

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