code: private static MethodHandle findMethod(Class<?> clazz, String methodName, boolean staticMethod,
        Class<?> expectedReturnType, Class<?>... expectedParameterTypes) {
      MethodHandle methodHandle = null;
      try {
        Method method = clazz.getMethod(methodName, expectedParameterTypes);
        int modifiers = method.getModifiers();
        Class<?> returnType = method.getReturnType();
        if (Modifier.isStatic(modifiers) != staticMethod) {
          throw new NoSuchMethodException();
        }
        if (expectedReturnType != null && !expectedReturnType.isAssignableFrom(returnType)) {
          throw new NoSuchMethodException();
        }
        methodHandle = MethodHandles.publicLookup().unreflect(method);
      } catch (NoSuchMethodException | SecurityException | IllegalAccessException e) {
        // Method not found
      }
      return methodHandle;
  
    }
docs: Finds and returns a method handle for the given criteria.
  
  @param clazz
  the class to search
  @param methodName
  the name of the method
  @param staticMethod
  whether the method is static or not
  @param expectedReturnType
  expected return type
  @param expectedParameterTypes
  expected parameter types
  @return a methodHandle for the specified criteria. Returns {@code null} if no method exists
  with the specified criteria.