Over a million developers have joined DZone.

Nice Netbeans Hint - The 'if' Statement is Redundant

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

I have no doubt about how useful NetBeans hints are for developers. I take advantage of them everyday for my work, both writing new code and refactoring existing code; and they only get better as new releases come out.

However, 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.

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}