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

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

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.

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}