I've recently started using Checkstyle set to use the Sun Coding standards. However, one of the messages I'm receiving is as follows:
- Avoid inline conditionals.
It is reporting it on the following line:
All this does is return an int from an ArrayList where Integer was used to store the int in the List.
I thought the line of code was an easy way to check for a null object. Could someone explain what the significance of "Avoid inline conditionals" is and how I should update my line of code, if its deemed to be not to standard?
That's the problem with automated style checkers: either you surrender to their recommendations, or you learn to live with ignoring some of the warnings.
I don't know about this particular checker, but it's possible that this form would make it complain about multiple return statements (another very dubious criticism, in my view.) Then you'd have to write
The only thing coming to my mind that could improve the code is removing the need for the null check at all - for example by applying the Null Object pattern.
But I use inline conditionals all the time - they often make the code much clearer, if used wisely. I'd advise to disable this specific check, it's silly.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus