Lambdas Flashcards

1
Q

Describe the Supplier Interface in Java

A

The first interface is the Supplier<T> interface. In a nutshell, a supplier does not take any arguments and returns an object.</T>

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

Describe the Consumer Interface in Java

A

The second interface is the Consumer<T> interface. A consumer does the opposite of the supplier: it takes an argument and does not return anything.</T>

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

You should be aware that, starting with Java SE 8, concrete methods are allowed in __. They can be instance methods, in that case, they are called __ methods, and they can be ___ methods. These methods do not count, since they are not ___ methods.

A lambda expression is an implementation of the only __ method in this functional interface. So finding the right method to implement is just a matter of finding this method.

A

You should be aware that, starting with Java SE 8, concrete methods are allowed in interfaces. They can be instance methods, in that case, they are called default methods, and they can be static methods. These methods do not count, since they are not abstract methods.

A lambda expression is an implementation of the only abstract method in this functional interface. So finding the right method to implement is just a matter of finding this method.

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

Do I need to add the annotation @FunctionalInterface on an interface to make it functional?

A

No you don’t. This annotation is here to help you to make sure that your interface is indeed functional. If you put this annotation on a type that is not a functional interface, then the compiler will raise an error.

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

What is the Predicate interface used for in Java?

A

A predicate is used to test an object. It is used for filtering streams in the Stream API

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

What is the Function interface method used for in Java

A

Function<T, R> interface. The abstract method of a function takes an object of type T and returns a transformation of that object to any other type U.

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