Java Class - getGenericInterfaces() Method
The java.lang.Class.getGenericInterfaces() method returns the Types representing the interfaces directly implemented by the class or interface represented by this object.
Syntax
public Type[] getGenericInterfaces()
Parameters
No parameter is required.
Return Value
Returns an array of interfaces implemented by this class.
Exception
- Throws GenericSignatureFormatError, if the generic class signature does not conform to the format specified in The Java Virtual Machine Specification.
- Throws TypeNotPresentException, if any of the generic superinterfaces refers to a non-existent type declaration.
- Throws MalformedParameterizedTypeException, if any of the generic superinterfaces refer to a parameterized type that cannot be instantiated for any reason.
Example:
The example below shows usage of the java.lang.Class.getGenericInterfaces() method.
import java.lang.*; import java.lang.reflect.*; public class MyClass { public static void main(String[] args) { try { Class cls = Class.forName("java.lang.Boolean"); //print accessible public methods Type t[] = cls.getGenericInterfaces(); System.out.println("Interfaces are: "); for(Type i: t) System.out.println(i); } catch (Exception e) { System.out.println(e); } } }
The output of the above code will be:
Interfaces are: interface java.io.Serializable java.lang.Comparable<java.lang.Boolean>
❮ Java.lang - Class