Nice Netbeans Hint - The 'if' Statement is Redundant
Join the DZone community and get the full member experience.
Join For FreeHowever, no matter how long I've been using it, I still am amazed at how clever my preferred IDE can be. I have seen all kinds of code, from very clever patterns usage and design to code so awful and naive that it could make James Gosling himself regret having created Java – not actually, but close :-).
A few days ago I was shocked by a piece of code like this:
private boolean redundantIf() { boolean condition = true; if(condition) { return true; } else { return false; } }
Of course, this is not the original one, but you get the idea. The most interesting thing was the yellow bulb besides the if line:

Of course, I could not help clicking on it, and this is what I saw:

And this was the result:

Add this to the inspect and transform feature, and your code will be cleaner and faster.
I'll leave you the homework to try this on at home:
private boolean redundantIf() { boolean condition = true; if(condition) { return false; } else { return true; } }Do you know any other good editor hint from NetBeans, or any other IDE? Please leave a comment about it. And if you are still reading this, thank you for your patience and time.
Opinions expressed by DZone contributors are their own.
Comments