Here you can find the source of getDeclaredInterfaces(Class claz, Class... assignableClasses)
Parameter | Description |
---|---|
claz | The class to get all interfaces. |
@SuppressWarnings("unchecked") public static List<Class<?>> getDeclaredInterfaces(Class claz, Class... assignableClasses)
//package com.java2s; /*//from ww w .j a va2 s .c om * Copyright (c) 2008-2016, GigaSpaces Technologies, Inc. All Rights Reserved. * * 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; import java.util.List; public class Main { /** * Returns an array of all declared interfaces of desired class (super-classes comes an * account). If <code>assignableClasses</code> is <code>null</code> all implemented interface * will be added to array, otherwise only <b>assignable</b> classes. * * @param claz The class to get all interfaces. **/ @SuppressWarnings("unchecked") public static List<Class<?>> getDeclaredInterfaces(Class claz, Class... assignableClasses) { ArrayList<Class<?>> interfList = new ArrayList<Class<?>>(); while (!claz.equals(Object.class)) { for (Class cl : claz.getInterfaces()) { /* append only assignable interfaces */ if (assignableClasses.length > 0) { for (Class assignClaz : assignableClasses) { if (assignClaz.isAssignableFrom(cl)) interfList.add(cl); } } else interfList.add(cl); } claz = claz.getSuperclass(); } return interfList; } }