Rob Spoor wrote:Lambdas can not just replace anonymous inner classes, they can also replace the need for template methods. Instead of creating an abstract base class that has abstract methods that need to be overridden, you can provide lambdas to provide that functionality.
A quick example from some code I've written some time ago; this class has a getter (String -> String), setter ((String, String) -> String) and a remover (String -> ()). Slightly simplified:
Before Java 8, I had to make this class abstract, and provide (anonymous) implementations for using a Map or System properties as a backing mechanism: