rspec/rules/S4197/java/rule.adoc

35 lines
782 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Comparator<Foo> compartor = (foo1, foo2) -> foo.getName().compareTo(foo2.getName()); // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Comparator<Foo> compartor = Comparator.comparing(Foo::getName);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]