Java Reflection Method Get from Object getMethodByName(Object target, String methodName)

Here you can find the source of getMethodByName(Object target, String methodName)

Description

get Method By Name

License

Open Source License

Declaration

private static Method getMethodByName(Object target, String methodName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Method;

public class Main {
    private static Method getMethodByName(Object target, String methodName) {
        Class<?> classToSearch = target.getClass();
        Method method = null;/*from  w ww .  j a v a2s.  c om*/

        do {
            try {
                method = classToSearch.getDeclaredMethod(methodName);
            } catch (SecurityException | NoSuchMethodException exception) {
                classToSearch = classToSearch.getSuperclass();
            }
        } while (method == null && classToSearch != null);

        return method;
    }
}

Related

  1. getMethod(Object target, String methodName)
  2. getMethod(Object target, String methodName, Class... parameterTypes)
  3. getMethod(Object target, String signature)
  4. getMethod(String methodName, Object instance)
  5. getMethodAnnotatedWith(final Class type, final Class annotation, String fieldName, Object fieldValue)
  6. getMethodConfigByAnnotaton(Object instance, Class declaringClass, Class annotationType, Class type)
  7. getMethodDescriptor(Object instance, String methodName, Class aClass, Class... parameters)
  8. getMethodFirstParamType(final String methodName, final Object o)
  9. getMethodIfAny(final Object instance, final String name, final Class[] params)