Because in a string concatenation operation null will be converted to "null"
automatically.
Useful in debugging this is.
ie:
log.debug("value of bob=" + bob);

is a lot easier than always having to write

if(bob == null)
  log.debug("value of bob=null");
else
  log.debug("value of bob=" + bob);

Which you would have to do if it was converted to an empty string, or threw
a NullPointerException if you tried to output it...

-----Original Message-----
From: Jagdish Arora [mailto:[EMAIL PROTECTED]]
Sent: Friday, 17 January 2003 16:31
To: Struts Users Mailing List
Subject: java.lang.String question disguised as an ActionForm question



ok, though this problem came up dealing with ActionForms, I completely
understand that this is a fundamental Java question, nothing more, so I will
pose it as that only.  Also, I am prepared for taking some
thisQuestion(OrYou)DoesntDeserveToBeHere flak:

        String s1 = "" + null;
        System.out.println ("s1: " + s1);
        if (s1 == null)
            System.out.println ("s1 is null");
        else
            System.out.println ("s1 is not null");

produces output:
        s1: null
        s1 is not null

While if I replace the first line by, String s1 = "";
then it produces output:
        s1:
        s1 is not null

(which I have no problem with).

Question: Why does the 1st line of the output of the first case read s1:
null  ?

Amrinder

--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to