@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.
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"));
convert("42") = 42
convertOrZero("oops") = 0
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