
Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
On Tue, 25 Oct 2005 13:04:10 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :
>if ( theWords != null && theWords.equals( "elephant" ) );
you can shorten that to:
if ( "elephant".equals( theWords) )
This effectively does the null test for free. The catch is, this code
tends to baffle novice programmers.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Bruce Lewis - 25 Oct 2005 19:16 GMT
> On Tue, 25 Oct 2005 13:04:10 GMT, Roedy Green
> <my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
[quoted text clipped - 8 lines]
> This effectively does the null test for free. The catch is, this code
> tends to baffle novice programmers.
More likely it surprises programmers with experience in languages where
strings are not objects with methods. For a truly novice programmer I
don't see why this should be more baffling than any other idiom.
Even for programmers surprised at this code, it's obvious what it does.
I think this style is a useful way to gain conciseness.