Java Reflection Generic Return Type getGenericReturnType(Method m)

Here you can find the source of getGenericReturnType(Method m)

Description

get Generic Return Type

License

Apache License

Declaration

public static Class<?> getGenericReturnType(Method m) 

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<?> getGenericReturnType(Method m) {
        Type t = m.getGenericReturnType();

        if (t instanceof ParameterizedType) {
            for (Type arg : ((ParameterizedType) t).getActualTypeArguments()) {
                return (Class) arg;
            }/*  www . ja va 2 s  .c  om*/
        }
        return null;
    }
}

Related

  1. getGenericClassFromMethodReturn(Method m)
  2. getGenericReturnClass(Method method)
  3. getGenericReturnTypeMap(Method method, boolean isAllowNull)
  4. getGenericReturnTypeOfGenericInterfaceMethod( Class clazz, Method method)
  5. getGenericReturnTypeOfGenericInterfaceMethod(Class clazz, Method method)
  6. getGenericType(Type returnType, int index)