« Alzheimer Oriented Architecture | Main | Complexity is Free »

How not to use equals in an if{} block

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

kasia
(June 22, 2003 05:39 PM #)

Personally.. I'm a big proponent of intern... so no equals :)

.. but I do know what you mean.

rajesh
(June 25, 2003 03:05 AM #)

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