get Interfaces Include Super Class - Java Reflection

Java examples for Reflection:Field Get

Description

get Interfaces Include Super Class

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Class clazz = String.class;
        System.out.println(getInterfacesIncludeSuperClass(clazz));
    }/*from   w  w  w.j a v  a2 s.co m*/

    public static List<Class<?>> getInterfacesIncludeSuperClass(
            final Class<?> clazz) {
        List<Class<?>> types = new ArrayList<Class<?>>();
        for (Class<?> superClass = clazz; superClass != Object.class; superClass = superClass
                .getSuperclass()) {
            for (Class<?> intf : superClass.getInterfaces()) {
                if (!types.contains(intf)) {
                    types.add(intf);
                }
            }
        }
        return types;
    }
}

Related Tutorials