Lambda Flashcards
Predicate<object> p</object>
Represents a predicate (boolean-valued function) of one argument.
This is a functional interface whose functional method is test(Object).
boolean test(T t)
Consumer
Interface Consumer<T>
Represents an operation that accepts a single input argument and returns no result
*accept(T t)
Performs this operation on the given argument.</T>
Functional interfaces
in package:java.util.function
Functional interfaces provide target types for lambda expressions and method references.
Function<T,R>
Represents a function that accepts one argument and produces a result.
This is a functional interface whose functional method is apply(Object).
return R :apply(T t)
Applies this function to the given argument.
Supplier<T></T>
Represents a supplier of results.
There is no requirement that a new or distinct result be returned each time the supplier is invoked.
This is a functional interface whose functional method is get().
T get()
UnaryOperator<T></T>
Represents an operation on a single operand that produces a result of the same type as its operand.
Lambda expressions
When you write a lambda expression for a functional interface, you are essentially providing an implementation of the method declared in that interface but in a very concise manner. Therefore, the lambda expression code that you write must contain all the pieces of the regular method code except the ones that the compiler can easily figure out on its own such as the parameter types, return keyword, and brackets. So, in a lambda expression, just check that all the information is there and that the expression follows the basic syntax -
(parameter list) OR single_variable_without_type ->
{ return expression; } OR just_an_expression_without_semicolon
*lambda expression does not create a new scope for variables!!!! Therefore, you cannot reuse the variable names that have already been used to define new variables in your argument list (It would be like defining the same variable twice in the same scope.)