While this is really a Java question and not a JSP issue it does give me a
chance to expound one of my favorite programming points. You should always
create code that handles unexpected conditions. A much better way to write
this is:

if ( "AT".equalsIgnoreCase( key ) ) {
 // do something
}

The reason is simple. "AT" is a constant and therefore never going to be an
unexpected value like null. It looks a little weird at first but it is
tremendously useful to know that this code can't break and almost certainly
a null value for key should be expected to not pass the equality test.

Another small point. The code is much better described in most cases by
using a named constant as in:

class x {
 public static final String AT_TEST = "AT";

 void testMethod( String key ) {
  if ( AT_TEST.equalsIgnoreCase( key ) ) {
    // do something
  }
 }
}

-----Original Message-----
From: Aaron Prohaska [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 07, 2000 3:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Problem with if statement


Thanks everyone. I actually used key.equalsIgnoreCase("AT") and its works
perfectly.

Aaron

                <<:::..:::...::: Aaron Prohaska :::..:::...:::>>
VerdeSoft Internet Services
mailto:[EMAIL PROTECTED]          http://www.verdesoft.net/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to