Java Utililty Methods Reflection Method Parameter

List of utility methods to do Reflection Method Parameter

Description

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

Method

OptionalgetMethod(Class type, String name, Class... parameterTypes)
get Method
try {
    return Optional.of(type.getDeclaredMethod(name, parameterTypes));
} catch (NoSuchMethodException e) {
    return Optional.empty();
MethodgetMethod(Class clazz, String methodName, Class[] parameterTypes)
This method return the list of method of any class.
Method method = null;
try {
    method = clazz.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
    if (methodName.startsWith("get")) {
        methodName = methodName.replaceFirst("get", "is");
    } else if (methodName.startsWith("is")) {
        methodName = methodName.replaceFirst("get", "is");
...
MethodgetMethod(final Class clazz, final String name, final Class... parameterTypes)
get Method
if (clazz == null) {
    throw new NoSuchMethodException(name + "() method not found.");
try {
    return clazz.getDeclaredMethod(name, parameterTypes);
} catch (Exception ex) {
    return getMethod(clazz.getSuperclass(), name, parameterTypes);
MethodgetMethod(final Class javaClass, final String methodName, final Class[] methodParameterTypes, final boolean shouldSetAccessible)
Get a method declared in the given class.
Method method = findMethod(javaClass, methodName, methodParameterTypes);
if (shouldSetAccessible) {
    method.setAccessible(true);
return method;
MethodgetMethod(final Class aClass, final String methodName, Class[] parameterTypes)
Warning : each call of this method should be tested with a JUnit test, in order to know when the API has changed
Method m = null;
m = aClass.getDeclaredMethod(methodName, parameterTypes);
m.setAccessible(true);
return m;
MethodgetMethod(final Class clazz, final String methodName, final Class... parameterTypes)
get Method
try {
    return clazz.getDeclaredMethod(methodName, parameterTypes);
} catch (final NoSuchMethodException ex) {
    return null;
MethodgetMethod(final Class clazz, final String name, final Class... parametertypes)
Get a method by name.
Method result = null;
for (final Method method : getMethods(clazz)) {
    if (method.getName().equals(name) && Arrays.equals(method.getParameterTypes(), parametertypes)) {
        result = method;
        break;
if (result == null)
...
MethodgetMethod(final Class clazz, final String name, final Class... parameterTypes)
Returns the matched public method of the specified class or null if no such method
try {
    return clazz.getMethod(name, parameterTypes);
} catch (final Exception e) {
    return null;
MethodgetMethod(final Class target, final String name, final Class... parameters)
Gets the method defined on the target class.
final String key = target.getName() + '.' + name;
Method method = METHOD_CACHE.get(key);
if (method != null) {
    return method;
try {
    method = target.getMethod(name, parameters);
    METHOD_CACHE.put(key, method);
...
MethodgetMethod(final Class receiver, final String methodName, final Class... parameterTypes)
get Method
try {
    return receiver.getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException | SecurityException e) {
    throw new RuntimeException(e);