Miles Daffin wrote:
>
> > Brett Bergquist wrote:
> > > Actually the test that you want is:
> > >
> > > if (user.compareTo("admin") == 0) {
> > > ...
> > > }
> >
> > And how is this any different from using
> > "if (user.equals("admin"))"?
> ...
> 'compareTo(Object o)' returns an int
> ...
> 'equals(Object o)' returns a boolean
A few notes:
1) java.lang.Comparable is new in Java2. It's not there
if you are running w/Java 1.1 (OK with Tomcat 3.x).
2) compareTo(), for Strings does a *lexical* comparison.
Semantically, this code wants to know that the user
is "admin", not that the user is lexically equivalent
to "admin". Using equals() describes the operation
semantically better than compareTo().
3) You should use:
"admin".equals(user)
That avoids a potential NullPointerException.
-- Charles