Lambda: A functional interface can carry default and static methods, only one abstract

@FunctionalInterface requires exactly one abstract method, but the interface can still declare any number of default and static methods alongside it, and a lambda only ever implements the single abstract one.

Code
interface Converter {
    int convert(String s);
    default int convertOrZero(String s) {
        try {
            return convert(s);
        } catch (NumberFormatException e) {
            return 0;
        }
    }
    static Converter identity() {
        return s -> Integer.parseInt(s);
    }
}
Converter c = Converter.identity();
System.out.println("convert(\"42\") = " + c.convert("42"));
System.out.println("convertOrZero(\"oops\") = " + c.convertOrZero("oops"));
Output
convert("42") = 42
convertOrZero("oops") = 0
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms