Here you can find the source of getGenericParameter(Type class1, int number)
Parameter | Description |
---|---|
class1 | a parameter |
number | a parameter |
public static Class getGenericParameter(Type class1, int number)
//package com.java2s; //License from project: Apache License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**//from w ww.j av a 2s . co m * Extract generic parameter from super class * @param class1 * @param number * @return */ public static Class getGenericParameter(Type class1, int number) { // assertArg("Not ParameterizedType", class1 instanceof ParameterizedType); ParameterizedType type = (ParameterizedType) class1; Type arg = type.getActualTypeArguments()[number]; if (arg instanceof Class) { return (Class) arg; } else if (arg instanceof ParameterizedType) { return (Class) ((ParameterizedType) arg).getRawType(); } else { throw new UnsupportedOperationException(); } } }