Java Utililty Methods Reflection Method Name

List of utility methods to do Reflection Method Name

Description

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

Method

MethodgetMethod(Class beanClass, String methodName, Class[] types)
get Method
return beanClass.getDeclaredMethod(methodName, types);
java.lang.reflect.MethodgetMethod(Class c, String name)
get Method
Method _method = null;
for (Method m : c.getMethods()) {
    if (m.getName().equalsIgnoreCase(name)) {
        _method = m;
        break;
return _method;
...
MethodgetMethod(Class c, String name)
Get method by name (declared)
for (Method m : c.getMethods()) {
    if (m.getName().equals(name))
        return m;
return null;
MethodgetMethod(Class c, String name, Class[] args)
Get method from class
Method m = null;
while (true) {
    try {
        m = c.getDeclaredMethod(name, args);
        break;
    } catch (NoSuchMethodException e) {
        c = c.getSuperclass();
        if (c == null) {
...
MethodgetMethod(Class clazz, String methodName)
get Method
return clazz.getMethod(methodName, (Class<?>[]) null);
MethodgetMethod(Class clazz, String methodName, Class fieldType)
get Method
String name = fieldType.getSimpleName();
if ("Boolean".equals(name)) {
    return clazz.getMethod(methodName, boolean.class);
if ("Integer".equals(name)) {
    return clazz.getMethod(methodName, int.class);
if ("Long".equals(name)) {
...
MethodgetMethod(Class clazz, String methodName, Class... arguments)
Fail-safe getMethod.
try {
    return clazz.getMethod(methodName, arguments);
} catch (NoSuchMethodException e) {
} catch (SecurityException e) {
return null;
MethodgetMethod(Class clazz, String methodName, Class... params)
get Method
try {
    return clazz.getDeclaredMethod(methodName, params);
} catch (NoSuchMethodException e) {
    throw new RuntimeException(
            String.format("Cannot find method (%s) on class (%s)", methodName, clazz.getCanonicalName()),
            e);
MethodgetMethod(Class clazz, String methodName, Class... params)
Get a method from a class that has the specific paramaters
if (!loadedMethods.containsKey(clazz)) {
    loadedMethods.put(clazz, new HashMap<String, Method>());
Map<String, Method> methods = loadedMethods.get(clazz);
if (methods.containsKey(methodName)) {
    return methods.get(methodName);
try {
...
MethodgetMethod(Class clazz, String methodName, Class... params)
get Method
try {
    return clazz.getDeclaredMethod(methodName, params);
} catch (NoSuchMethodException e) {
    Class<?> superClass = clazz.getSuperclass();
    if (superClass == null) {
        throw e;
    } else {
        return getMethod(superClass, methodName, params);
...