What is a functional interface? When do you use a lambda versus a method reference?
Short answer
A functional interface has exactly one unimplemented (abstract) method, so a short lambda can stand in for it.
3 points to say:
- Extra
defaultandstaticmethods are fine. - Common ones:
Function,Predicate,Consumer,Supplier. - A lambda that only calls an existing method becomes
User::getName.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.