Java Utililty Methods Reflection Method Get from Object

List of utility methods to do Reflection Method Get from Object

Description

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

Method

MethodgetMethod(Class type, String name, Object[] args)
get Method
return selectMethod(getMethods(type, name), args);
MethodgetMethod(final Class clazz, final String methodName, final Class[] parTypes, final Object[] parameters)
get Method
assert clazz != null && methodName != null && parTypes != null && parameters != null;
try {
    return clazz.getDeclaredMethod(methodName, parTypes);
} catch (NoSuchMethodException e) {
    final Class<?> superClass = clazz.getSuperclass();
    if (superClass != null) {
        return getMethod(superClass, methodName, parTypes, parameters);
    throw e;
MethodgetMethod(final Object object, final String methodName, final Class... parameterClass)
get Method
return getMethod(object.getClass(), methodName, parameterClass);
MethodgetMethod(final Object object, final String methodName, final Object... arguments)
Returns object's method with the specified name and arguments.
return getMethod(object.getClass(), methodName, arguments);
ObjectgetMethod(final Object object, final String methodName, final Object... arguments)
get Method
final Class<?> c = object.getClass();
final Class<?>[] parameterTypes = new Class<?>[arguments.length];
int counter = 0;
for (final Object argument : arguments) {
    parameterTypes[counter++] = argument.getClass();
final Method method = c.getDeclaredMethod(methodName, parameterTypes);
return method;
...
MethodgetMethod(final Object object, String methodName, final Class[] argTypes)
get Method
final Method method;
try {
    method = object.getClass().getMethod(methodName, argTypes);
} catch (Exception e) {
    throw new IllegalArgumentException("Exception when retrieving method " + methodName + " by reflection",
            e);
return method;
...
MethodgetMethod(final Object target, final String methodName, final Class... argumentTypes)
Returns a the specified method of the target object, or null if the method does not exist.
return getMethod(target.getClass(), methodName, argumentTypes);
MethodgetMethod(final String methodName, final Object obj, final Class... argTypes)
Returns a method (public or private) object for the given methodName if it exists.
Method method = null;
try {
    method = obj.getClass().getDeclaredMethod(methodName, argTypes);
    method.setAccessible(true);
} catch (final SecurityException e) {
    throw new RuntimeException(e);
} catch (final NoSuchMethodException e) {
    throw new RuntimeException(e);
...
MethodgetMethod(Object bean, String propertyName)
Return the named getter method on the bean or null if not found.
final StringBuilder sb = new StringBuilder("get").append(Character.toUpperCase(propertyName.charAt(0)));
if (propertyName.length() > 1) {
    sb.append(propertyName.substring(1));
final String getterName = sb.toString();
for (Method m : bean.getClass().getMethods()) {
    if (getterName.equals(m.getName()) && m.getParameterTypes().length == 0) {
        return m;
...
OptionalgetMethod(Object instance, String methodName, Class... argsClass)
get Method
try {
    return Optional.of(instance.getClass().getMethod(methodName, argsClass));
} catch (NoSuchMethodException | SecurityException e) {
    e.printStackTrace();
return Optional.empty();