Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashSet;

import java.util.Set;

public class Main {
    public static Set<Class<?>> findSuperTypes(Class<?> targetClass) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        Class<?> clazz = targetClass;
        while (clazz != null) {
            classes.add(clazz);
            addInterfaces(classes, clazz.getInterfaces());
            clazz = clazz.getSuperclass();
        }
        return classes;
    }

    private static void addInterfaces(Set<Class<?>> types, Class<?>[] interfaces) {
        for (Class<?> interfaceClass : interfaces) {
            types.add(interfaceClass);
            addInterfaces(types, interfaceClass.getInterfaces());
        }
    }
}