Here you can find the source of getGenericType(Class clazz, int index)
Parameter | Description |
---|---|
clazz | Class |
index | Index of the Generic Type |
Parameter | Description |
---|---|
IllegalArgumentException | when the Class does not have a Generic Type at the specified position or has none. |
public static Type getGenericType(Class clazz, int index) throws IllegalArgumentException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**/* w w w . j a va 2 s . co m*/ * Find the Generic Type of the form {@code Class<GenericType>}. * * @param clazz Class * @param index Index of the Generic Type * @throws IllegalArgumentException when the Class does not have a Generic Type at the specified position or has none. * @return Generic Type */ public static Type getGenericType(Class clazz, int index) throws IllegalArgumentException { ParameterizedType type = (ParameterizedType) clazz.getGenericSuperclass(); if (type.getActualTypeArguments() == null || type.getActualTypeArguments().length <= index) { throw new IllegalArgumentException("No generic type at the specified position"); } return type.getActualTypeArguments()[index]; } }