Home » Java programming language

Java Class class getGenericInterfaces() method with example

Class class getGenericInterfaces() method: Here, we are going to learn about the getGenericInterfaces() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 22, 2019

Class class getGenericInterfaces() method

  • getGenericInterfaces() method is available in java.lang package.
  • getGenericInterfaces() method is used to return an array denoting the interfaces implemented by the class or an interface denoted by this object.
  • getGenericInterfaces() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • getGenericInterfaces() method may throw an exception at the time of returning an array of interfaces.
    • GenericSignatureFormatError: This exception may raise when the generic class signature does not match the format given in the JVM Specification.
    • TypeNotPresentException: This exception may raise when any generic parent interfaces refer to a non-existent type.
    • MalformedParameterizedTypeException: This exception may throw when any generic parent interfaces refer to a parameterized type that cannot be initialized.


    public Type[] getGenericInterfaces();


  • It does not accept any parameter.

Return value:

The return type of this method is Type[], it returns an array of interfaces implemented by the class.


// Java program to demonstrate the example 
// of Type[]  getGenericInterfaces () method of Class 

import java.lang.reflect.*;

public class GetGenericInterfacesOfClass {
 public static void main(String[] args) {
  StringBuilder sb = new StringBuilder();
  Class cl = sb.getClass();

  // It returns an array of interfaces objects that is
  // implemented by the Class

  Type[] ty = cl.getGenericInterfaces();

  if (ty.length != 0)
   for (int i = 0; i < ty.length; ++i) {
    System.out.print("Interfaces implemented by StringBuilder: ");
   System.out.println("No interface implemented by StringBuilder ");


Interfaces implemented by StringBuilder: interface
Interfaces implemented by StringBuilder: java.lang.Comparable<java.lang.StringBuilder>
Interfaces implemented by StringBuilder: interface java.lang.CharSequence


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.