# Replace Assignment with Compound Operator
Assignments involving an arithmetic assignment can be simplified by using a compound operator such as
For example, this rule will transform
The rule only applies if both operands are primitive types.
Applying this rule leads to more simplicity in the code base and thus improves readability.
# Code Changes
# Operator +=
i = i + 3; i = 3 + i; i = i + (3 + 4);
i += 3; i += 3; i += (3 + 4);
# Operator -=
i = i - 3; i = -3 + i; i = i - (3 + 4);
i -= 3; i += -3; i -= (3 + 4);
# Operator *=
i = i * 3; i = i * (3 + 4);
i *= 3; i *= (3 + 4);
# Operator /=
i = i / 3; i = i / (3 + 4);
i /= 3; i /= (3 + 4);
Rule can be applied only on the following types:
Use a Java Refactoring Tool
No license required
You can review this refactoring on your code without a license by installing jSparrow to your Eclipse IDE. Install the plug-in from Eclipse IDE: Eclipse Marketplace.
Do you want to automate this refactoring (and many more) to your system-wide code? The automatic application of this system-wide refactoring can be unlocked by acquiring your jSparrow license.
|First seen in jSparrow version||1.0.0|
|Minimum Java version||1.4|
|Remediation cost||2 min|