Geeta Ramani wrote:
>
> Hmm, really? I thought that since String is not a primitive data type, when you
> pass a String to a variable, you are passing a reference to that String obect,
> (and it is not passed by value)..? So my guess would have been that doing a
> "putValue" wouldnt have been necessary.. Of course it should easy enough to
> check..

And if you had checked it before leaping to reply, you would have
found...

h.get("myInfo") is [this is string 1]
myInfoB is [This is an entirely different string]

------------------ test code ------------------------------
import java.util.*;

public class Test {
  public static void main(String[] args) {
    Hashtable h = new Hashtable();
    String myInfo = "this is string 1";
    h.put("myInfo", myInfo);

    //simulate servlet b with a different myInfo variable
    String myInfoB = (String) h.get("myInfo");
    myInfoB = "This is an entirely different string";

    System.out.println("h.get(\"myInfo\") is [" + h.get("myInfo") +
"]");
    System.out.println("myInfoB is [" + myInfoB + "]");
  }
}
------------------ test code ------------------------------

You are partly right. A reference to the string is passed to the session
object. When servlet B gets the string from the session, it is really
getting a reference to the string. That reference is assigned to some
variable. If a new reference is assigned to that variable, the reference
inside the session object is unchanged-- it still points to the original
string object. Assigning a new reference (of ANY type) to a new variable
does not change the references held by other variables.

___________________________________________________________________________
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