6.2 Introducing Functional Interfaces Flashcards
📝️ What friend can help us remember what is a functional interface?
Our dear friend SAM, because a Functional Interface contains a Single Abstract Method aka (SAM)
📝️ What annotation does Java provide to confirm an Interface is Functional?
@FunctionalInterface
📝️ What package is specifically designed to contain only functional interfaces that are reused in the rest of the library?
java.util.function
📝️ What are the 4 fundamental predefined Functional Interfaces?
Predicate -> boolean test(T t)
Function -> R apply(T t)
Consumer -> void accept(T t)
Supplier -> T get()
📝️ What feature does java.lang.Comparable provides?
single-sorting sequence
-> In other words, we can sort the collection on the basis of a 🧠️single element🧠️ such as id, name, or price. (It’s predefined Natural sort)
📝️ Does Comparable interface affects the original class?
Yes, It performs a 💥️Mutable💥️ process
📝️ What is the S.A.M of Comparable?
Comparable :: int compareTo(T o);
📝️ What features does java.util.Comparator provides?
multiple-sorting sequence
-> We can sort a collection on the basis of 🧠️multiple elements🧠️
📝️ Does Comparator interface affects the original class?
No, , It performs an💥️Immutable💥️ process
📝️ What is the S.A.M of Comparator?
Comparator :: int compare(T o1, T o2);