With lambdas as part of the Java language more possible implementations have opened up. Where before we may have used an alternate pattern such as maybe the Template Method Pattern where a subclass overrides a method to specialize the behavior of the superclass, we can now use a factory method that takes a lambda that serves as the specialization function.
Let’s look at another example, LinkedHashMap. This can serve as a cache by overriding the
removeEldestEntry which gets invoked on each
put operation with the oldest item…