30 lines
625 B
Plaintext
30 lines
625 B
Plaintext
== Why is this an issue?
|
|
|
|
When an assignment is made in a return statement, the assigned value is returned and the assignment does take place. But if the assigned variable is local to the method, the assignment itself is simply wasted code.
|
|
|
|
|
|
Whether the variable is local or not, it makes for confusing code that will leave maintainers scratching their heads, wondering at the real intent.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,text]
|
|
----
|
|
public int getNumber() {
|
|
int a = 0;
|
|
return a = 8; // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,text]
|
|
----
|
|
public int getNumber() {
|
|
int a = 0;
|
|
return 8;
|
|
}
|
|
----
|
|
|