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

MethodgetMethod(final Field visitee, final String methodName, final Class... parameterTypes)
Gets the method specified by methodName for the optionally specified parameterTypes from the specified visitee 's declaring class.
Method result = null;
try {
    result = visitee.getDeclaringClass().getMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
    throw new RuntimeException("Unable to access method " + methodName + " for field:" + visitee.toString(),
            e);
return result;
...
MethodgetMethod(String classFullName, String methodName, Class... parameterTypes)
get Method
Class<?> cls = getClass(classFullName);
if (cls == null || "".equals(methodName)) {
    return null;
Method method = null;
try {
    method = cls.getDeclaredMethod(methodName, parameterTypes);
} catch (SecurityException | NoSuchMethodException e) {
...
MethodgetMethod0(Class c, String name, Class... parameterTypes)
Invokes private Class.getMethod0() without throwing NoSuchMethodException.
try {
    return (Method) _getMethod0.invoke(c, name, parameterTypes);
} catch (Exception ignore) {
    return null;
MethodgetMethod0(Class target, String name, Class[] parameterTypes)
get Method
try {
    Method method = target.getDeclaredMethod(name, parameterTypes);
    method.setAccessible(true);
    return method;
} catch (NoSuchMethodException ignored) {
Class<?> superclass = target.getSuperclass();
if (superclass != null) {
...
Annotation[]getMethodAnnotations(String className, String methodName, Class[] parameterTypes)
Returns all annotations on the given method
try {
    Class<?> cls = Class.forName(className);
    if ("<init>".equals(methodName)) {
        Constructor<?> c = cls.getDeclaredConstructor(parameterTypes);
        c.setAccessible(true);
        return c.getAnnotations();
    } else {
        try {
...
MethodgetMethodByName(Class clazz, String name, Class... parameterTypes)
get Method By Name
return getMethodByName(clazz, null, name, parameterTypes);
MethodgetMethodByParametersWithAnnotation(final Class source, final Class[] params, final Class annotation)
get Method By Parameters With Annotation
for (final Method e : source.getDeclaredMethods()) {
    if (Arrays.deepEquals(e.getParameterTypes(), params)) {
        if (e.isAnnotationPresent(annotation)) {
            return e;
return null;
...
MethodgetMethodFromClass(String className, String methodName, Class... parameterTypes)
get Method From Class
Class<?> c = Class.forName(className);
return c.getMethod(methodName, parameterTypes);
MethodgetMethodFromClassName(String classAndMethodName, Class... parameterTypes)
Returns a method from the class and method name string.
int lastIdx = classAndMethodName.lastIndexOf('.');
if (lastIdx == -1) {
    throw new IllegalArgumentException("classAndMethodName must be in form of <class>.<method>");
String className = classAndMethodName.substring(0, lastIdx);
String methodName = classAndMethodName.substring(lastIdx + 1);
Class<?> clazz = Class.forName(className);
return clazz.getMethod(methodName, parameterTypes);
...
StringgetMethodFullName(Method m, boolean includeClassPackage, boolean includeParametersType, boolean includeTypesPackage)
get Method Full Name
String str;
str = includeClassPackage ? m.getClass().getName() : m.getClass().getSimpleName() + "." + m.getName() + "(";
if (!(m.getParameterTypes().length == 0) && includeParametersType) {
    for (int i = 0; i < m.getParameterTypes().length; i++) {
        str = str + (includeTypesPackage ? m.getParameterTypes()[i].getName()
                : m.getParameterTypes()[i].getSimpleName());
        if (!(i == m.getParameterTypes().length - 1))
            str = str + ", ";
...