I have the following statement to check if a Vector2D is within a box, and IntelliJ gives me a warning: "if statement can be simplified".
if(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY)
return false;
How can I simplify this?
I don't see any possible simplification. I would just ignore the warning.
Update: However, if you method look like this:
if(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY)
return false;
return true;
You might change it to this:
return !(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY);
Or even:
return point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY;
I don't know if this is "simplified" for humans.
Whenever IntelliJ warns of a possible simplification, it often offers to perform the simplification (by clicking the yellow light bulb). What happens if you do that?
I would just do this.
return !(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY);
and it would remove the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With