code: public static Optional<MethodUsage> getFunctionalMethod(ResolvedReferenceTypeDeclaration typeDeclaration) {
          //We need to find all abstract methods
          Set<MethodUsage> methods = typeDeclaration.getAllMethods().stream()
                  .filter(m -> m.getDeclaration().isAbstract())
                  // Remove methods inherited by Object:
                  // Consider the case of Comparator which define equals. It would be considered a functional method.
                  .filter(m -> !declaredOnObject(m))
                  .collect(Collectors.toSet());
  
          if (methods.size() == 1) {
              return Optional.of(methods.iterator().next());
          } else {
              return Optional.empty();
          }
      }
docs: Get the functional method defined by the type, if any.