All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S1604.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

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.

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

Note that this rule is automatically disabled when the project's java.source.version is lower than 8.

Noncompliant Code Example

myCollection.map(new Mapper<String,String>() {
  public String map(String input) {
    return new StringBuilder(input).reverse().toString();
  }
});

Compliant Solution

myCollection.map(element -> new StringBuilder(element).reverse().toString());




© 2015 - 2025 Weber Informatics LLC | Privacy Policy