Java.lang.Class.getInterfaces() Method
Advertisements
Description
The java.lang.Class.getInterfaces() determines the interfaces implemented by the class or interface represented by this object.
Declaration
Following is the declaration for java.lang.Class.getInterfaces() method
public Class<?>[] getInterfaces()
Parameters
NA
Return Value
This method returns an array of interfaces implemented by this class.
Exception
NA
Example
The following example shows the usage of java.lang.Class.getInterfaces() method.
package com.tutorialspoint;
import java.lang.*;
import java.util.*;
public class ClassDemo {
public static void main(String[] args) {
show(Thread.class);
}
public static void show(Class cls) {
System.out.println("Class = " + cls.getName());
Class[] c = cls.getClasses();
System.out.println("Classes = " + Arrays.asList(c));
// returns an array of interfaces
Class[] i = cls.getInterfaces();
System.out.println("Interfaces = " + Arrays.asList(i));
}
}
Let us compile and run the above program, this will produce the following result:
Class = java.lang.Thread Classes = [interface java.lang.Thread$UncaughtExceptionHandler, class java.lang.Thread$State] Interfaces = [interface java.lang.Runnable]