Java Reflection Interface Get getInterfaces(Object owner, String[] interfaceStrings)

Here you can find the source of getInterfaces(Object owner, String[] interfaceStrings)

Description

get interface classes which the object implemented

License

Apache License

Parameter

Parameter Description
owner target object
interfaceStrings target interface strings

Return

target interface classes

Declaration

public static ArrayList<Class<?>> getInterfaces(Object owner, String[] interfaceStrings) 

Method Source Code

//package com.java2s;
/*/*from w  w w.ja  v a  2 s .c o m*/
 * Copyright (C) 2011 Baidu.com Inc
 *
 * 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://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;

public class Main {
    /**
     * get interface classes which the object implemented
     * 
     * @param owner
     *            target object
     * @param interfaceStrings
     *            target interface strings
     * @return target interface classes
     */
    public static ArrayList<Class<?>> getInterfaces(Object owner, String[] interfaceStrings) {
        ArrayList<Class<?>> targetInterfaces = new ArrayList<Class<?>>();
        Class<?>[] interfaceClasses = owner.getClass().getInterfaces();
        for (Class<?> interfaceClass : interfaceClasses) {
            for (String interfaceName : interfaceStrings) {
                if (interfaceClass.getName().contains(interfaceName)) {
                    targetInterfaces.add(interfaceClass);
                }
            }
        }
        return targetInterfaces;
    }
}

Related

  1. getInterfaces(Class clazz)
  2. getInterfaces(Class c)
  3. getInterfaces(Class clazz)
  4. getInterfaces(Class clazz)
  5. getInterfaces(final Class type)
  6. getInterfacesForClass(Class type)
  7. getInterfacesList(Class clazz)
  8. getParentAllInterfaces(Class pojoClass)
  9. getPortNameAndSuffixFromInterfaceName( String intfName)