September 2019
Intermediate to advanced
816 pages
18h 47m
English
Mark comes up with some good news the next day – he will extend his business and sell other fruits as well as melons. This is cool, but our predicate only supports Melon instances.
So, how should we proceed to support other fruits too? How many other fruits? What if Mark decides to start selling another category of products, such as vegetables? We cannot simply create a predicate for each of them. This will take us back to the start.
The obvious solution is to abstract the List type. We start this by defining a new interface, and this time name it Predicate (remove Melon from the name):
@FunctionalInterfacepublic interface Predicate<T> { boolean test(T t);}
Next, we rewrite the filterMelons() method and rename ...