Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Nice Netbeans Hint - The 'if' Statement is Redundant

DZone's Guide to

Nice Netbeans Hint - The 'if' Statement is Redundant

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

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.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}