Example:
int x = a - a; // redundant; can be replaced with 0 int y = a + 0; // redundant; can be replaced with a double res = d / d; // redundant; can be replaced with 1.0
Note that in rare cases, the suggested replacement might not be completely equivalent of the original code
for all possible inputs. E.g. the inspection suggests to replace x / x
with 1
.
However, if x
happens to be zero, the original code throws ArithmeticException or results in NaN.
Also, if x
is NaN, then the result is also NaN. It's very unlikely that such a behavior is intended.