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

MethodgetMethod(Class clazz, String methodName, Class returnType, Class... inputParams)
get Method
if (inputParams == null) {
    inputParams = new Class<?>[0];
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
    if (method.getName().equals(methodName) && returnType.isAssignableFrom(method.getReturnType())
            && Arrays.equals(inputParams, method.getParameterTypes())) {
        return method;
...
MethodgetMethod(Class clazz, String name, String returnType, String[] args)
get Method
Method[] methods = clazz.getDeclaredMethods();
MainLoop: for (Method method : methods) {
    if (name != null && !name.equals(method.getName())) {
        continue;
    if (returnType != null && !returnType.equals(method.getReturnType().getName())) {
        continue;
    if (args != null) {
        Class<?>[] args2 = method.getParameterTypes();
        if (args2.length != args.length) {
            continue;
        for (int count = 0; count < args.length; count++) {
            if (!(args[count].equals(args2[count].getName()))) {
                continue MainLoop;
    return method;
return null;
MethodgetMethod(Class parentClass, Class returnType, String methodName, Class... types)
get Method
for (Method method : parentClass.getDeclaredMethods()) {
    if (equalsTo(method, returnType, methodName, types))
        return method;
return null;
MethodgetMethod(Class type, String name, Class returnType, Class paramType, boolean caseSensitive)
Gets the public method within the type that matches the method name, return type, and single parameter type.
boolean methodNameFound = false;
Class<?> classType = type;
while (classType != null && !classType.equals(Object.class)) {
    for (Method m : classType.getDeclaredMethods()) {
        if ((!caseSensitive && m.getName().equalsIgnoreCase(name))
                || (caseSensitive && m.getName().equals(name))) {
            methodNameFound = true;
            if (returnType != null) {
...
MethodgetMethodByReturnType(final Class source, final Class type)
get Method By Return Type
for (final Method e : source.getDeclaredMethods()) {
    if (e.getReturnType().isAssignableFrom(type)) {
        return e;
return null;
MethodgetMethodByTypes(Class clazz, String name, Class returnType, Class... parameterTypes)
get Method By Types
for (Method method : clazz.getDeclaredMethods()) {
    if (!Modifier.isPublic(method.getModifiers())) {
        continue;
    if (method.getReturnType().equals(returnType)
            && Arrays.equals(method.getParameterTypes(), parameterTypes)) {
        return method;
throw new RuntimeException(name + " not found in " + clazz);
StringgetMethodDesc(Class returnType, Class... params)
get Method Desc
StringBuilder sb = new StringBuilder("(");
for (Class<?> c : params) {
    sb.append(getDesc(c));
sb.append(')');
sb.append(getDesc(returnType));
return sb.toString();
MethodgetMethode(Class clasS, Class Returntype, int modifier, Class... classes)
get Methode
for (Method m : clasS.getDeclaredMethods()) {
    if (HasParametersignature(m, classes) && m.getReturnType().isAssignableFrom(Returntype)
            && m.getModifiers() == modifier)
        return m;
return null;
ClassgetMethodGenericReturnType(Method method, Class rawType, int index)
get Method Generic Return Type
Type returnType = method.getGenericReturnType();
return getGenericType(returnType, rawType, index);
ClassgetMethodGenericReturnType(Method method, int index)
get Method Generic Return Type
return getGenericType(method.getGenericReturnType(), index);