Java Reflection - Class.getInterfaces() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public Class<?>[] getInterfaces()
Returns:
an array of interfaces implemented by this class.

Examples


package com.logicbig.example.clazz;

import java.io.Serializable;

public class GetInterfacesExample {

public static void main(String... args) {
Class<MyClass> c = MyClass.class;
Class<?>[] interfaces = c.getInterfaces();
for (Class<?> anInterface : interfaces) {
System.out.println(anInterface);
}
}

private static class MyClass implements Serializable, Runnable{
@Override
public void run() {

}
}

}

Output

interface java.io.Serializable
interface java.lang.Runnable




package com.logicbig.example.clazz;

import java.io.Serializable;

public class GetInterfacesExample2 {

public static void main(String... args) {
Class<MyInterface> c = MyInterface.class;
Class<?>[] interfaces = c.getInterfaces();
for (Class<?> anInterface : interfaces) {
System.out.println(anInterface);
}
}

private static interface MyInterface extends Serializable, Runnable {}
}

Output

interface java.io.Serializable
interface java.lang.Runnable




See Also