15.1_Working with Built‐in Functional Interfaces Flashcards
📝️ What are the most Common functional interfaces?
T - Supplier - get
void - Consumer | BiConsumer - accept
R - Function | BiFunction | UnaryOperator | BinaryOperator - apply
boolean - Predicate | BiPredicate - test
📝️ What is a Supplier?
A Supplier is used when you want to generate or supply values without taking any input.
🤓️ A Supplier is often used when constructing new objects.
🤯️⚠️📣️ Supplier suppLd = LocalDate::now;
🤯️⚠️📣️ Supplier suppSb = StringBuilder::new;
🤯️⚠️📣️ Supplier> suppAl = ArrayList::new;
📝️ What is a Cosumer?
🤓️ You use a Consumer when you want to do something with a parameter but not return anything.
🤓️ BiConsumer does the same thing except that it takes two parameters.
📝️ What is a Predicate?
🤓️ Predicate is often used when filtering or matching.
🤓️ A BiPredicate is just like a Predicate except that it takes two parameters instead of one.
📝️ What is a Function?
🤓️ A Function is responsible for turning one parameter into a value of a potentially different type and returning it. 🤓️ Similarly, a BiFunction is responsible for turning two parameters into a value and returning it.
📝️ What are UnaryOperator and BinaryOperator?
UnaryOperator and BinaryOperator, are a special case of a Function.
- > A UnaryOperator transforms its value into one of the same type. (e.g: Incrementing by one)
- > A BinaryOperator merges two values into one of the same type. (e.g: Adding two numbers)