Here you can find the source of getInterfaces(Class> clazz)
Gets a List
of all interfaces implemented by the given class and its superclasses.
Parameter | Description |
---|---|
clazz | the class to look up, may be <code>null</code> |
List
of interfaces in order, null
if null input
public static List<Class<?>> getInterfaces(Class<?> clazz)
//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; } }