2021-04-28 16:49:39 +02:00
|
|
|
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++``.
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
x -> {System.out.println(x+1);}
|
|
|
|
(a, b) -> { return a+b; }
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
x -> System.out.println(x+1)
|
|
|
|
(a, b) -> a+b //For return statement, the return keyword should also be dropped
|
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
|
|
|
|