Lambdas Flashcards

1
Q

Lambdas usage

A

*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; });

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Functional interfaces

A

**Functional interfaces provide target types for lambda expressions and method references???

in package java.util.function:

  1. Consumer<T>
    void accept(T t)</T>
  2. Predicate<T>
    boolean test(T t)</T>

3.Supplier<T>
T get()</T>

  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly