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(Object object, String methodName, Class... arguments)
get Method
return object.getClass().getDeclaredMethod(methodName, arguments);
MethodgetMethod(Object object, String name, Object... params)
get method by name
try {
    List<Class> classParams = new ArrayList<>();
    for (int i = 0; i < params.length; i++) {
        classParams.add((Class) params[i]);
    Class<?> classParamsArray[] = new Class[classParams.size()];
    classParams.toArray(classParamsArray);
    return object.getClass().getMethod(name, classParamsArray);
...
MethodgetMethod(Object oo, String mname)
get Method
try {
    Method method = oo.getClass().getMethod(toMethodName(mname), new Class[] { String.class });
    return method;
} catch (Exception ex) {
    return null;
MethodgetMethod(Object pojo, String methodName, Class[] params)
get Method
Method method = null;
Class<?> cClass = pojo.getClass();
while (cClass != null && method == null) {
    try {
        method = cClass.getDeclaredMethod(methodName, params);
    } catch (NoSuchMethodException nsf) {
        cClass = cClass.getSuperclass();
return method;
MethodgetMethod(Object target, String methodName)
get Method
Method result = (Method) METHODS.get(methodName);
if (result == null) {
    Object[] argTypes = (Object[]) METHOD_ARGS.get(methodName);
    result = getMethod(target, methodName, argTypes);
    METHODS.put(methodName, result);
return result;
MethodgetMethod(Object target, String methodName, Class... parameterTypes)
Get target method
try {
    return target.getClass().getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
    throw new IllegalArgumentException(e);
MethodgetMethod(Object target, String signature)
get Method
Assert.isNotNull(target);
Assert.isNotNull(signature);
Class<?> targetClass = getTargetClass(target);
while (targetClass != null) {
    for (Method method : targetClass.getDeclaredMethods()) {
        if (getMethodSignature(method).equals(signature)) {
            method.setAccessible(true);
            return method;
...
MethodgetMethod(String methodName, Object instance)
get Method Name
Method[] methods = instance.getClass().getMethods();
for (Method m : methods) {
    if (m.getName().equalsIgnoreCase(methodName)) {
        return m;
return null;
MethodgetMethodAnnotatedWith(final Class type, final Class annotation, String fieldName, Object fieldValue)
get Method Annotated With
List<Method> methods = getMethodsAnnotatedWith(type, annotation);
for (Method m : methods)
    try {
        Annotation an = m.getAnnotation(annotation);
        Method anMethod = an.annotationType().getDeclaredMethod(fieldName);
        Object value = anMethod.invoke(an);
        if (value.toString().equals(fieldValue))
            return m;
...
MethodgetMethodByName(Object target, String methodName)
get Method By Name
Class<?> classToSearch = target.getClass();
Method method = null;
do {
    try {
        method = classToSearch.getDeclaredMethod(methodName);
    } catch (SecurityException | NoSuchMethodException exception) {
        classToSearch = classToSearch.getSuperclass();
} while (method == null && classToSearch != null);
return method;