java8
Categories of Functional Interfaces and Predicate vs Function vs Supplier.
4 Main Categories:
- Predicate
: Takes one argument, returns boolean. (e.g.,test(T t)) - Function<T, R>: Takes one argument, returns a result. (e.g.,
apply(T t)) - Supplier
: Takes no argument, returns a result. (e.g., get()) - Consumer
: Takes one argument, returns nothing ( void). (e.g.,accept(T t))
Differences:
- Predicate: Used for filtering/logic checks.
- Function: Used for transforming data from one type to another.
- Supplier: Used for lazy generation of values.