Java Method .getGenericParameterTypes ()

Syntax

Method.getGenericParameterTypes() has the following syntax.

public Type [] getGenericParameterTypes()

Example

In the following code shows how to use Method.getGenericParameterTypes() method.


import java.lang.reflect.Method;
import java.lang.reflect.Type;
import static java.lang.System.out;
/*from ww w.j a v  a2s .  c  om*/
public class Main {
  private static final String fmt = "%24s: %s%n";

  <E extends RuntimeException> void genericThrow() throws E {
  }

  public static void main(String... args) {
    try {
      Class<?> c = Class.forName("Main");
      Method[] allMethods = c.getDeclaredMethods();
      for (Method m : allMethods) {
        Class<?>[] pType = m.getParameterTypes();
        Type[] gpType = m.getGenericParameterTypes();
        for (int i = 0; i < pType.length; i++) {
          out.format(fmt, "ParameterType", pType[i]);
          out.format(fmt, "GenericParameterType", gpType[i]);
        }
      }
    } catch (ClassNotFoundException x) {
      x.printStackTrace();
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable