code: public static Method getMethod(Class<?> clazz, String name, boolean withParameters) {
          if (clazz == Object.class || clazz == null) {
              return null;
          }
  
          try {
              // first try without parameters
              Method method = clazz.getDeclaredMethod(name);
              return method;
          } catch (SecurityException e) {
              throw new IllegalStateException(e);
          } catch (NoSuchMethodException e) {
              if (withParameters) {
                  Method[] methods = getMethods(clazz);
                  for (Method method : methods) {
                      if (name.equals(method.getName())) {
                          return method;
                      }
                  }
                  return null;
              }
              return getMethod(clazz.getSuperclass(), name, withParameters);
          }
      }
docs: Gets a method of a class by name.
  
  @param clazz
  @param name
  @param withParameters
  whether or not to include methods with parameters
  @return