Java Reflection Interface Get getAllInterfaces(Class clazz)

Here you can find the source of getAllInterfaces(Class clazz)

Description

Returns the set of interfaces implemented by the given class and its ancestors or a blank set if none

License

Apache License

Declaration

public List<Class<?>> getAllInterfaces(Class<?> clazz) 

Method Source Code

//package com.java2s;
/*//  w w w .j a v  a  2s  . co m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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.ArrayList;

import java.util.List;

public class Main {
    /**
     * Returns the set of interfaces implemented by the given class and its
     * ancestors or a blank set if none
     */
    public List<Class<?>> getAllInterfaces(Class<?> clazz) {
        List<Class<?>> implemented = new ArrayList<Class<?>>();
        getAllInterfaces(clazz, implemented);
        return implemented;
    }

    private static void getAllInterfaces(Class<?> clazz, List<Class<?>> implemented) {
        Class<?>[] interfaces = clazz.getInterfaces();
        for (Class<?> interfaze : interfaces) {
            if (!implemented.contains(interfaze)) {
                implemented.add(interfaze);
            }
        }
        Class<?> superClass = clazz.getSuperclass();
        // Object has no superclass so check for null
        if (superClass != null && !superClass.equals(Object.class)) {
            getAllInterfaces(superClass, implemented);
        }
    }
}

Related

  1. getAllInterfaces(Class clazz)
  2. getAllInterfaces(Class cls)
  3. getAllInterfaces(Class cls)
  4. getAllInterfaces(Class base)
  5. getAllInterfaces(Class clazz)
  6. getAllInterfaces(Class clazz)
  7. getAllInterfaces(Class cls)
  8. getAllInterfaces(Class cls)
  9. getAllInterfaces(Class type)