rspec/rules/S4197/java/rule.adoc
2021-04-28 18:08:03 +02:00

20 lines
535 B
Plaintext

Java 8 adds ``++Comparator.comparing++`` to allow the creation of a single-value comparator to be shorthanded into a single call. This cleaner syntax should be preferred.
*Note* that this rule is automatically disabled when the project's ``++sonar.java.source++`` is lower than ``++8++``.
== Noncompliant Code Example
----
Comparator<Foo> compartor = (foo1, foo2) -> foo.getName().compareTo(foo2.getName()); // Noncompliant
----
== Compliant Solution
----
Comparator<Foo> compartor = Comparator.comparing(Foo::getName);
----