rspec/rules/S1602/java/rule.adoc
2022-02-04 16:28:24 +00:00

40 lines
780 B
Plaintext

There are two ways to write lambdas that contain single statement, but one is definitely more compact and readable than the other.
*Note* that this rule is automatically disabled when the project's ``++sonar.java.source++`` is lower than ``++8++``.
== Noncompliant Code Example
[source,java]
----
x -> {System.out.println(x+1);}
(a, b) -> { return a+b; }
----
== Compliant Solution
[source,java]
----
x -> System.out.println(x+1)
(a, b) -> a+b //For return statement, the return keyword should also be dropped
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]