Java 怎么获取由指定类(包括其本身)扩展的类和实现的接口的集合

李逍遥
17407
文章
5
评论
2019年7月5日20:09:04 评论 857字阅读2分51秒

1.简介

Java 怎么获取由指定类(包括其本身)扩展的类和实现的接口的集合?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 Copyright 2005-2006 Seth Fitzsimmons <seth@mojodna.net>

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http:

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */


import java.util.Collection;
import java.util.HashSet;

public class Main {


    
    private static Collection<Class> getClasses(Class clazz) {
        final Collection<Class> classes = new HashSet<Class>();
        while (null != clazz) {
            classes.add(clazz);

            
            for (final Class iface : clazz.getInterfaces()) {
                classes.add(iface);
            }

            clazz = clazz.getSuperclass();
        }
        return classes;
    }
}

 
展开全文
  • 版权声明: 发表于 2019年7月5日20:09:04
  • 转载注明:https://www.tah1986.com/10514.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: