集册 Java实例教程 获取所有接口的设置

获取所有接口的设置

欢马劈雪     最近更新时间:2020-01-02 10:19:05

572
获取所有接口的设置


import java.lang.reflect.Array;

import java.lang.reflect.Constructor;
/** from 
时 代      J a v a   公   众 号 - nowjava.com**/

import java.lang.reflect.Method;

import java.lang.reflect.Modifier;

import java.net.URL;

import java.util.Collections;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Set;

import java.util.WeakHashMap;


public class Main{

    public static Set<Class<?>> getAllInterfacesAsSet(Class<?> clazz,

            ClassLoader classLoader) {

        if (clazz == null)/* from N o w  J a v a  .   c o m*/

            return null;

        if (clazz.isInterface() && isVisible(clazz, classLoader)) {

            Set<Class<?>> set = CollectionUtil.createHashSet(1);

            set.add(clazz);

            return set;

        }

        Set<Class<?>> interfaces = CollectionUtil.createLinkedHashSet();

        while (clazz != null) {

            Class<?>[] ifcs = clazz.getInterfaces();

            for (Class<?> ifc : ifcs) {

                interfaces.addAll(getAllInterfacesAsSet(ifc, classLoader));

            }

            clazz = clazz.getSuperclass();

        }

        return interfaces;

    }

    public static boolean isVisible(Class<?> clazz, ClassLoader classLoader) {

        if (classLoader == null) {

            return true;

        }

        try {

            Class<?> actualClas
展开阅读全文