Java Reflection Generic Return Type getGenericClassFromMethodReturn(Method m)

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

Description

get Generic Class From Method Return

License

Apache License

Declaration

public static Class getGenericClassFromMethodReturn(Method m)
            throws Exception 

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 getGenericClassFromMethodReturn(Method m)
            throws Exception {
        Type type = m.getGenericReturnType();

        if (type instanceof ParameterizedType) {
            ParameterizedType pt = (ParameterizedType) type;
            return (Class) pt.getActualTypeArguments()[0];
        }/*from   w w w  .j a v  a 2  s.  co  m*/
        return null;
    }
}

Related

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