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

Apache License

Declaration

public static Class getMethodGenericReturnType(Method method, int index) 

Method Source Code

//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);
    }
}

Related

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