Card 09/ 09
Recap: Lambdas and Functional Interfaces
What a lambda is, the interfaces it lands in, method references and captured variables, with where each was.
Lambdas come down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| A lambda is an object implementing an interface, chosen by where it is passed | Lambdas: Passing Behaviour to a Method as an Argument |
| A functional interface has exactly one abstract method | Functional Interfaces: Exactly One Abstract Method |
Function, Predicate, Consumer and Supplier cover almost everything | Function vs Predicate vs Consumer vs Supplier |
| A method reference replaces a lambda that only passes its parameters through | Method References, and When a Lambda Is Clearer |
| Captured locals must never be reassigned, because the lambda holds a copy | Captured Variables: Why a Lambda Cannot Change a Local |
A lambda has no type of its own. Its parameter types, its return type and what it may touch all come from the parameter it was handed to, and reading that parameter is how you read the lambda.
← → move through sections and cards