How not to use equals in an if{} block
June 22, 2003 |
co.mments
kasia in a nutshell: The abuse and over-use of toString()
The scary part is how many experienced programmers have no clue about this little gotcha.. go spread the word.
Yikes. And there's the following related anti-idiom :
public void foo(Object whatever)
{
if(whatever.equals(THE_CONSTANT))
...
}
Every time I see this, it breaks my heart.
June 22, 2003 05:35 PM
Comments
Personally.. I'm a big proponent of intern... so no equals :)
.. but I do know what you mean.
use StringUtils from jakarta commons lang it checks for null and keeps your code clean
Trackback Pings
TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1010