Lambdas Flashcards
Describe the Supplier Interface in Java
The first interface is the Supplier<T> interface. In a nutshell, a supplier does not take any arguments and returns an object.</T>
Describe the Consumer Interface in Java
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>
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.
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.
Do I need to add the annotation @FunctionalInterface on an interface to make it functional?
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.
What is the Predicate interface used for in Java?
A predicate is used to test an object. It is used for filtering streams in the Stream API
What is the Function interface method used for in Java
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.