Java.lang Package Classes

Java Class - getGenericSuperclass() Method



The java.lang.Class.getGenericSuperclass() method returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class.

Syntax

public Type getGenericSuperclass()

Parameters

No parameter is required.

Return Value

Returns the superclass of the class represented by this object.

Exception

  • Throws GenericSignatureFormatError, if the generic class signature does not conform to the format specified in The Java Virtual Machine Specification.
  • Throws TypeNotPresentException, if the generic superclass refers to a non-existent type declaration.
  • Throws MalformedParameterizedTypeException, if the generic superclass refers to a parameterized type that cannot be instantiated for any reason.

Example:

The example below shows usage of the java.lang.Class.getGenericSuperclass() 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.getGenericSuperclass();
      System.out.print("Super Class is: ");
      System.out.println(t);
        
    } catch (Exception e) {
      System.out.println(e);
    }
  }
}

The output of the above code will be:

Super Class is: class java.lang.Object

❮ Java.lang - Class