Here you can find the source of getGenericTypeArguments(Method m, int i)
Parameter | Description |
---|---|
m | Method we want to probe generic type arguments. |
i | the i'th parameter of the method. |
public static Type[] getGenericTypeArguments(Method m, int i)
//package com.java2s; /**/* w w w . j a v a 2 s .c o m*/ * Copyright (c) 2014-2015 by Wen Yu. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Any modifications to this file must keep this entire header intact. */ import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /** * @param m Method we want to probe generic type arguments. * @param i the i'th parameter of the method. * @return an array of parameterized Types for the i'th argument or an empty array. */ public static Type[] getGenericTypeArguments(Method m, int i) { try { Type t = m.getGenericParameterTypes()[i]; if (t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) t; return pt.getActualTypeArguments(); } } catch (Exception e) { System.out.println("Error probing generic type arguments!"); } return new Type[] {}; } }