java-symbol-solver-logic/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java
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();
        }
    }
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();
        }
    }
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 ( ) ; } }
Get the functional method defined by the type, if any.
Get the functional method defined by the type if any .