Lambdas Flashcards
Can lambdas be generic?
No, but the functional interfaces they implement can be generic
What is a lambda expression?
A lambda expression is an anonymous method used to implement the abstract method of a functional interface
What is a functional interface?
A functional interface is an interface with only one abstract method
Is it possible to explicitly specify the type of a parameter in a lambda expression?
Yes, but is it not necessary since the parameter type can be inferred from the functional interface
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
True
When is a lambda expression instantiated?
Whenever it is assigned to a funtional interface type
Can a lambda expression modify the local variables of its enclosing scope?
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++; }
What are the 4 main functional interfaces provided by java and their associated abstract methods?
void Consumer.accept(T t)
R Function.apply(T t)
boolean Predicate.test(T t)
T Supplier.get()