Java Reflection Method Return getMethodGenericReturnType(Method method, int index)

Here you can find the source of getMethodGenericReturnType(Method method, int index)

Description

get Method Generic Return Type

License

Open Source License

Declaration

public static Class getMethodGenericReturnType(Method method, int index) 

Method Source Code


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

import java.lang.reflect.*;

public class Main {
    public static Class getMethodGenericReturnType(Method method, int index) {
        return getGenericType(method.getGenericReturnType(), index);
    }// w  ww  .j  a  va2s  . c  o m

    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);
            }
            return (Class) typeArguments[index];
        }
        return (Class) returnType;
    }
}

Related

  1. getMethodByReturnType(final Class source, final Class type)
  2. getMethodByTypes(Class clazz, String name, Class returnType, Class... parameterTypes)
  3. getMethodDesc(Class returnType, Class... params)
  4. getMethode(Class clasS, Class Returntype, int modifier, Class... classes)
  5. getMethodGenericReturnType(Method method, Class rawType, int index)
  6. getMethodGenericReturnType(Method method, int index)
  7. getMethodInvoker(final Class returnType, final String methodName)
  8. getMethodNoArgs(final Class objClass, final String methodName, final Class... returnTypePreference)
  9. getMethodReturnType(Class clazz, String methodName)