Geeta Ramani wrote:
>
> Properly chastised, (;-), I went ahead and tested several things in a trivial
> extension of Kevin's Test class and after some reading concluded that i was indeed
> wrong, and Kevin was indeed right. Apparantly the fact that String is an "immutable"
> class is the underlying reason for the fact that a putValue is neccessary for String
> objects, but, not needed for say, StringBuffer objects or Vector objects or Array
> objects (or probably most anything else?). So I guess the fact that it is a String is
> sort of special. Hopefully i am not too far off..?
It's not the fact the a String is immutable, but the fact the a NEW
REFERENCE was assigned to the local variable. Assigning a NEW REFERENCE
to a local variable does not change the reference held by the session.
------------------ test code ------------------------------
import java.util.*;
public class Test {
public static void main(String[] args) {
Hashtable h = new Hashtable();
StringBuffer myInfo = new StringBuffer("this is string 1");
h.put("myInfo", myInfo);
//simulate servlet b with a different myInfo variable
StringBuffer myInfoB = (StringBuffer) h.get("myInfo");
System.out.println("h.get(\"myInfo\") is [" + h.get("myInfo") +
"]");
System.out.println("myInfoB is [" + myInfoB + "]\n");
myInfoB = new StringBuffer("This is an entirely different string");
System.out.println("h.get(\"myInfo\") is [" + h.get("myInfo") +
"]");
System.out.println("myInfoB is [" + myInfoB + "]");
}
}
------------------ test code ------------------------------
___________________________________________________________________________
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