15.1_Working with Built‐in Functional Interfaces Flashcards

1
Q

📝️ What are the most Common functional interfaces?

A

T - Supplier - get
void - Consumer | BiConsumer - accept
R - Function | BiFunction | UnaryOperator | BinaryOperator - apply
boolean - Predicate | BiPredicate - test

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

📝️ What is a Supplier?

A

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;

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

📝️ What is a Cosumer?

A

🤓️ 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.

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

📝️ What is a Predicate?

A

🤓️ Predicate is often used when filtering or matching.

🤓️ A BiPredicate is just like a Predicate except that it takes two parameters instead of one.

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

📝️ What is a Function?

A

🤓️ 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.

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

📝️ What are UnaryOperator and BinaryOperator?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly