----- Original Message -----
From: Duke Martin <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 13, 1999 1:57 AM
Subject: will this code work?


> String temp = null;
> temp = process_me(temp);
>
> out.println(temp);
>
> public String process_me(String temp)
> {
> temp = "my name";
> return temp;
> }
>
> I would like to this the output of this servlet to print "my name" to the
> screen.  Will this work?
>
> thanks
>
Yes.

Returning the string is redundant but makes you code absolutely clear for
others reading it.
What actually happens in the code is this,

Object handle to temp is passed to the method.
The handle is replaced by the new String handle for "my name".
This handle is returned by the method.

This is because String objects are immutable (ie changing the contents of a
String actually causes a new String object to be
created and the handle to that new String is put in temp)

The old handle to temp w�ll become available for garbage collection.

Amazing load of spam for a simple question really

Andy Bailey

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to