> <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.
True, other than the overhead of calling String.intern() when the class is
loaded (JLS 3.10.5).
> ("".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.
False. If the compiler can inline equals(), it can inline length(), too.
(In fact, it's more likely to inline length(), since it's a far simpler
method.)
(And take a look at the source for String.equals(): at best, with comparable
inlining of the two methods, you've added an "instanceof" and a downcast,
which likely swamps any time taken for the rest of the comparison.)
-- Bill K.