rspec/rules/S4197/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

41 lines
855 B
Plaintext

== Why is this an issue?
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
[source,java]
----
Comparator<Foo> compartor = (foo1, foo2) -> foo.getName().compareTo(foo2.getName()); // Noncompliant
----
=== Compliant solution
[source,java]
----
Comparator<Foo> compartor = Comparator.comparing(Foo::getName);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Simplify this code with the use of "Comparator.comparing" instead.
=== Highlighting
the comparator definition
endif::env-github,rspecator-view[]