Here you can find the source of getMethodGenericReturnType(Method method, int index)
public static Class getMethodGenericReturnType(Method method, int index)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { public static Class getMethodGenericReturnType(Method method, int index) { Type returnType = method.getGenericReturnType(); if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; Type[] typeArguments = type.getActualTypeArguments(); if (index >= typeArguments.length || index < 0) { throw new IllegalArgumentException("index " + (index < 0 ? " must > 0 " : " over total arguments")); }// www. ja v a 2 s . c o m return (Class) typeArguments[index]; } return Object.class; } public static Class getMethodGenericReturnType(Method method) { return getMethodGenericReturnType(method, 0); } }