Lambdas Flashcards
Lambdas usage
*You need to put the parameter list of the lambda expression in brackets if you want to use the parameter type. For example,
checkList(new ArrayList(), (List al) -> al.isEmpty());
*Specifying the parameter type is optional ( as shown in option 1) because the compiler can figure out the parameter types by looking at the signature of the abstract method of any functional interface
*You need to put the body withing curly braces if you want to use the return keyword. For example,
checkList(new ArrayList(), al -> { return al.size() == 0; });
Functional interfaces
**Functional interfaces provide target types for lambda expressions and method references???
in package java.util.function:
- Consumer<T>
void accept(T t)</T> - Predicate<T>
boolean test(T t)</T>
3.Supplier<T>
T get()</T>
- Function<T,R>
R apply(T t)
*T - the type of the input to the function
*R - the type of the result of the function