Lambdas
Anonymous functions, or lambdas, can be used to instantiate functional interfaces.
Having these methods:
They can be used like this:
This will create a Function which calls the onRead method with the received argument.
As functional interfaces have a single method the conversion won't be ambiguous. It can or can not transform the operation into the interface.
Avoiding pass-through lambdas
The previous example is using a lambda just to pass an argument to the function. This can be avoided by using the other functional patterns:
Avoid using lambdas just to pass arguments into functions.
Last updated
Was this helpful?