Java Reflection - Java Class.getGenericSuperclass()








Syntax

Class.getGenericSuperclass() has the following syntax.

public Type getGenericSuperclass()

Example

In the following code shows how to use Class.getGenericSuperclass() method.

/*w  w w.j av  a 2 s .c om*/
import java.lang.reflect.*;
import java.util.ArrayList;

public class Main {

  public static void main(String args[]) {

    Type t = IntegerClass.class.getGenericSuperclass();
    System.out.println(t);

    ParameterizedType p = (ParameterizedType) t;
    System.out.println(p.getActualTypeArguments()[0]);
  }
}

class IntegerClass extends ArrayList<Integer> {
  public IntegerClass() {
    // no argument constructor
  }
}

The code above generates the following result.