Java Reflection Generic Return Type getGenericType(Type returnType, int index)

Here you can find the source of getGenericType(Type returnType, int index)

Description

get Generic Type

License

Open Source License

Declaration

public static Class getGenericType(Type returnType, int index) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.*;

public class Main {
    public static Class getGenericType(Type returnType, int index) {
        if (returnType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType) returnType;
            Type[] typeArguments = type.getActualTypeArguments();
            if (index >= typeArguments.length || index < 0) {
                throw new RuntimeException("invalid index : " + index);
            }/*  www.  j ava  2 s.c  o m*/
            return (Class) typeArguments[index];
        }
        return (Class) returnType;
    }
}

Related

  1. getGenericReturnClass(Method method)
  2. getGenericReturnType(Method m)
  3. getGenericReturnTypeMap(Method method, boolean isAllowNull)
  4. getGenericReturnTypeOfGenericInterfaceMethod( Class clazz, Method method)
  5. getGenericReturnTypeOfGenericInterfaceMethod(Class clazz, Method method)