Lambdas Flashcards

1
Q

Can lambdas be generic?

A

No, but the functional interfaces they implement can be generic

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

What is a lambda expression?

A

A lambda expression is an anonymous method used to implement the abstract method of a functional interface

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

What is a functional interface?

A

A functional interface is an interface with only one abstract method

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

Is it possible to explicitly specify the type of a parameter in a lambda expression?

A

Yes, but is it not necessary since the parameter type can be inferred from the functional interface

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

True or False

When a block lambda seems overly long to embed in a method call, it is possible to assign that lambda to a functional interface variable. Then, you can simply pass that reference to the method

A

True

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

When is a lambda expression instantiated?

A

Whenever it is assigned to a funtional interface type

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

Can a lambda expression modify the local variables of its enclosing scope?

A

No. The local variables of a lambda’s enclosing scope should be effectively final.

For example, the following code is illegal:

Supplier<Integer> incrementor(int start) {
  return () -> start++;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 4 main functional interfaces provided by java and their associated abstract methods?

A
  1. void Consumer.accept(T t)
  2. R Function.apply(T t)
  3. boolean Predicate.test(T t)
  4. T Supplier.get()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly