Java Utililty Methods Reflection Method Return

List of utility methods to do Reflection Method Return

Description

The list of methods to do Reflection Method Return are organized into topic(s).

Method

ClassgetMethodGenericReturnType(Method method, int index)
get Method Generic Return Type
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"));
    return (Class) typeArguments[index];
...
FunctiongetMethodInvoker(final Class returnType, final String methodName)
get Method Invoker
return new Function<Object, T>() {
    public T apply(Object from) {
        if (from == null)
            return null;
        try {
            Method method = from.getClass().getMethod(methodName, new Class[0]);
            return returnType.cast(method.invoke(from, new Object[0]));
        } catch (SecurityException e) {
...
MethodgetMethodNoArgs(final Class objClass, final String methodName, final Class... returnTypePreference)
Direct getMethod attempt.
try {
    final Method methodFound = objClass.getMethod(methodName);
    if (methodFound != null) {
        if (returnTypePreference == null || returnTypePreference.length == 0) {
            return methodFound;
        final Class<?> returnType = methodFound.getReturnType();
        for (int i = 0; i < returnTypePreference.length; i++) {
...
ClassgetMethodReturnType(Class clazz, String methodName)
Returns return type of given method in given class.
try {
    Method method = clazz.getDeclaredMethod(methodName);
    return method.getReturnType();
} catch (NoSuchMethodException e) {
    throw new AssertionError(e);
} catch (SecurityException e) {
    throw new AssertionError(e);
ClassgetMethodReturnType(Class clazz, String name)
Returns a Class object that identifies the declared class as a return type for the method represented by the given String name parameter inside the invoked Class clazz parameter.
if (clazz == null || name == null || name.isEmpty()) {
    return null;
name = name.toLowerCase();
Class<?> returnType = null;
for (Method method : clazz.getDeclaredMethods()) {
    if (method.getName().equals(name)) {
        returnType = method.getReturnType();
...
ClassgetMethodReturnType(Class clazz, String name)
get Method Return Type
if (clazz == null || name == null || name.isEmpty()) {
    return null;
name = name.toLowerCase();
Class<?> returnType = null;
for (Method method : clazz.getDeclaredMethods()) {
    if (method.getName().equals(name)) {
        returnType = method.getReturnType();
...