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

Method[]getMethods(Class clazz, String name, int args)
get Methods
try {
    List<Method> list = new ArrayList<Method>();
    for (Method method : clazz.getDeclaredMethods()) {
        if (method.getParameterTypes().length == args) {
            method.setAccessible(true);
            list.add(method);
    for (Method method : clazz.getDeclaredMethods())
        if (method.getParameterTypes().length == args)
            list.add(method);
    return list.toArray(new Method[list.size()]);
} catch (Throwable error) {
    return null;
Method[]getMethods(Class type, String name)
get Methods
return Arrays.stream(type.getMethods()).filter(m -> name.equals(m.getName())).toArray(Method[]::new);
ListgetMethods(final Class cl, final String name, final int params)
Gets all the methods with the given name in the given class or super classes.
final List result = new LinkedList();
if (cl.isInterface()) {
    final Method[] ms = cl.getDeclaredMethods();
    for (int i = 0; i < ms.length; i++) {
        if (ms[i].getName().equals(name) && ms[i].getParameterTypes().length == params) {
            result.add(ms[i]);
    final Class[] cs = cl.getInterfaces();
    for (int i = 0; i < cs.length; i++) {
        result.addAll(getMethods(cs[i], name, params));
    if (cs.length == 0) {
        result.addAll(getMethods(Object.class, name, params));
} else {
    Class c = cl;
    while (c != null) {
        final Method[] ms = c.getDeclaredMethods();
        for (int i = 0; i < ms.length; i++) {
            if (ms[i].getName().equals(name) && ms[i].getParameterTypes().length == params) {
                result.add(ms[i]);
        c = c.getSuperclass();
return result;
ListgetMethods(final Class clazz, final String methodName)
Find at the class all methods where its name be equals to the method name as parameter.
Method[] arrayMethod = clazz.getMethods();
List<Method> resultMethodList = new ArrayList<Method>();
for (Method currentMethod : arrayMethod) {
    if (currentMethod.getName().equalsIgnoreCase(methodName)) {
        resultMethodList.add(currentMethod);
return resultMethodList;
...
StringgetMethods(String classname)
get Methods
return (getMethods(Class.forName(classname)));
ListgetMethodsByName(Class cls, String methodName)
Find all methods with a specific name on a class regardless of parameter signature.
List<Method> methods = new ArrayList<Method>();
for (Method method : cls.getDeclaredMethods()) {
    if (method.getName().equals(methodName)) {
        methods.add(method);
return methods;
StringgetMethodSubjectName(Method method)
get Method Subject Name
String subjectName;
String methodName = method.getName();
if (methodName.startsWith("get"))
    subjectName = methodName.substring(3);
else if (methodName.startsWith("is"))
    subjectName = methodName.substring(2);
else
    subjectName = methodName;
...
Method[]getMethodsWithName(Class clazz, String name)
get Methods With Name
Method[] methods = clazz.getMethods();
return getMethodsWithName(methods, name);
TypegetMethodType(Class clazz, String methodName)
get Method Type
try {
    Method method = clazz.getMethod(methodName);
    return method.getGenericReturnType();
} catch (Exception ex) {
    return null;
StringgetMethodUniqueName(Method method)
get Method Unique Name
try {
    StringBuilder sb = new StringBuilder();
    sb.append(method.getDeclaringClass().getName()).append('.');
    sb.append(method.getName()).append('(');
    Class<?>[] params = method.getParameterTypes();
    if (params != null) {
        for (int j = 0; j < params.length; j++) {
            sb.append(getTypeName(params[j]));
...