<p>Before Java 8, the only way to partially support closures in Java was by using anonymous inner classes. But the syntax of anonymous classes may seem unwieldy and unclear.</p>

<p>With Java 8, most uses of anonymous inner classes should be replaced by lambdas to highly increase the readability of the source code.</p>

<h2>Noncompliant Code Example</h2>
<pre>
myCollection.map(new Mapper<String,String>() {
  public String map(String input) {
    return new StringBuilder(input).reverse().toString();
  }
});
</pre>

<h2>Compliant Solution</h2>
<pre>
myCollection.map(element -> new StringBuilder(element).reverse().toString());
</pre>