Java Utililty Methods Reflection Interface Get

List of utility methods to do Reflection Interface Get

Description

The list of methods to do Reflection Interface Get are organized into topic(s).

Method

List>getDeclaredInterfaces(Class claz, Class... assignableClasses)
Returns an array of all declared interfaces of desired class (super-classes comes an account).
ArrayList<Class<?>> interfList = new ArrayList<Class<?>>();
while (!claz.equals(Object.class)) {
    for (Class cl : claz.getInterfaces()) {
        if (assignableClasses.length > 0) {
            for (Class assignClaz : assignableClasses) {
                if (assignClaz.isAssignableFrom(cl))
                    interfList.add(cl);
        } else
            interfList.add(cl);
    claz = claz.getSuperclass();
return interfList;
voidgetImplementedInterfaceParents(Class clazz, Set classesResult)
get Implemented Interface Parents
Class[] interfaces = clazz.getInterfaces();
if (interfaces == null) {
    return;
for (int i = 0; i < interfaces.length; i++) {
    classesResult.add(interfaces[i]);
    getImplementedInterfaceParents(interfaces[i], classesResult);
ListgetImplementedInterfaces(Class clazz)
Returns the list of interfaces implemented by the class clazz.
List<String> list = new ArrayList();
Class[] classes = clazz.getInterfaces();
for (Class c : classes) {
    list.add(c.getCanonicalName());
    list.addAll(getImplementedInterfaces(c));
return list;
Set>getImplementedInterfaces(Class cl)
get Implemented Interfaces
Set<Class<?>> interfaces = new HashSet<Class<?>>();
Deque<Class<?>> classes = new ArrayDeque<Class<?>>();
classes.add(cl);
while (!classes.isEmpty()) {
    Class<?> c = classes.pop();
    interfaces.addAll(Arrays.asList(c.getInterfaces()));
    if (c.getSuperclass() != null) {
        classes.add(c.getSuperclass());
...
TgetInterfaceInstance(Class interfaceType)
get Interface Instance
Class impl = interfaceImplementations.get(interfaceType);
if (impl == null) {
    throw new InstantiationException("Cannot instantiate interface [ " + interfaceType.getName() + "]");
return (T) impl.newInstance();
String[]getInterfaceNames(Class c)
get Interface Names
Class<?>[] interfaces = c.getInterfaces();
List<String> names = new ArrayList<String>();
for (Class<?> i : interfaces) {
    names.add(i.getName());
return names.toArray(new String[interfaces.length]);
Class[]getInterfaces(Class clazz)
get Interfaces
List interfaces = new ArrayList();
interfaces = getAllInterfacesExclude(clazz, null, interfaces);
return (Class[]) (Class[]) interfaces.toArray(new Class[interfaces.size()]);
Class[]getInterfaces(Class c)
get Interfaces
List<Class<?>> result = new ArrayList<>();
if (c.isInterface()) {
    result.add(c);
} else {
    do {
        addInterfaces(c, result);
        c = c.getSuperclass();
    } while (c != null);
...
Class[]getInterfaces(Class clazz)
get Interfaces
if (clazz.isInterface())
    return new Class[] { clazz };
ArrayList<Class<?>> list = new ArrayList<>();
do
    for (Class<?> iface : clazz.getInterfaces()) {
        if (!list.contains(iface))
            list.add(iface);
while ((clazz = clazz.getSuperclass()) != null);
return list.toArray(new Class[0]);
List>getInterfaces(Class clazz)

Gets a List of all interfaces implemented by the given class and its superclasses.

if (clazz == null)
    return new ArrayList<Class<?>>(0);
List<Class<?>> list = new ArrayList<Class<?>>();
while (clazz != null) {
    Class<?>[] interfaces = clazz.getInterfaces();
    for (Class<?> interface1 : interfaces) {
        if (list.contains(interface1) == false)
            list.add(interface1);
...