See remarks below.

> -----Ursprüngliche Nachricht-----
> Von: John Baker [mailto:[EMAIL PROTECTED]]
> Gesendet: Donnerstag, 9. August 2001 09:55
> An: [EMAIL PROTECTED]
> Betreff: Re: Using Tomcat with MSAccess
<snip />
> >     "".equals(passwd)
> > rather than
> >     passwd.equals( "" )
<snip />
> No you shouldn't. That's totally evil. For a start, you're 
> creating another String object by doing ""
<snip/>
<remark>
  As "" is a constant string, it is created just once. So there
  is not much overhead. ("".equals might be even faster, because 
  the jit can inline the method call, as the address of the object 
  and the equals method is constant in this case.
</remark>
> and to add to this, you're saying it's ok to pass null to 
> equals. Passing null to the equals method is an awful idea. 
<remark>
  Why ? "".equals(null) returns false, that what you wan't 
  in most cases. (That return value is not implementation 
  specific, it's granted by the API.)

</remark>
> You actually want:
> 
> if ((passwd != null) && (passwd.lenght() == 0)) {
>    // Then do something
> }
<snip/>
<remark>
  That's wrong, to be equivalent to ("".equals(passwd)) 
  it should be:

  if ((passwd == null) || (passwd.lenght() == 0)) {
     // Then do something
  }
</remark>

Reply via email to