Unnecessary unary minus
Reports unnecessary unary minuses. Such expressions might be hard to understand and might contain errors.
For example:
void unaryMinus(int i) {
int x = - -i;
}
The following quick fixes are suggested here:
Remove
-
operators before thei
variable:void unaryMinus(int i) { int x = i; }Replace
-
operators with the prefix decrement operator:void unaryMinus(int i) { int x = --i; }
Another example:
void unaryMinus(int i) {
i += - 8;
}
After the quick-fix is applied:
void unaryMinus(int i) {
i -= 8;
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023