IntelliJ Hilarity

Note that this is a very lame post. IntelliJ IDEA is the greatest Java IDE in the world, his post does not “diss” it in any way, just pointing out something that was funny to me and only so because I’ve been at it for quite some time now.

I often have IntelliJ generate the equals() and hashCode() methods for me when programming @Entity beans. Here’s what it did for me:

equals

Makes sense, but notice how the last if statement is highlighted? That’s IntelliJ’s way of telling me that it can make things better which is a little weird because IntelliJ’s the guy that generated the code for me. Anyway, I see what the hint has to say:

hint

It’s saying that it can make some of these ifs redundant and sure enough once I take the hint the return clause is joined with last if like so:

first-hint

It’s all good but notice now that it now highlighted the previous if statement and if I accept it, it’ll continue doing the same thing over and over again. I’ll accept all the improvements it wants to make and I’ll finally end up with this method which is logically equivalent to what I showed you in the first picture:

final

The difference isn’t that great in an entity with three properties but you get the point about tertiary statements and IntelliJ”s love for them.

About these ads

One thought on “IntelliJ Hilarity

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s