Java Reflection - Java Constructor .getTypeParameters ()








Syntax

Constructor.getTypeParameters() has the following syntax.

public TypeVariable <Constructor <T>>[] getTypeParameters()

Example

In the following code shows how to use Constructor.getTypeParameters() method.

import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.TypeVariable;
//w  ww .ja va  2 s.  co m
public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class c = Class.forName("java.util.List");

    Constructor[] constructors = c.getDeclaredConstructors();
    for (int i = 0; i < constructors.length; i++) {
      print_method_or_constructor(constructors[i]);
    }

  }

  public static void print_method_or_constructor(Member member) {
    Constructor c = (Constructor) member;
    TypeVariable[] parameters = c.getTypeParameters();

    for (int i = 0; i < parameters.length; i++) {
      System.out.println(parameters[i]);
    }
  }
}