Bruce Bantos wrote:

> I put an object reference into the session with the following code:
>
>         session.putValue("mybean", mybean);
>
> I then retrieve the object later in the code to make an addition:
>
>         TheBean thebean = (TheBean)session.getValue("mybean");
>
>         thebean.setName("this is the bean name");
>
> Now, at this point isn't the bean Name for BOTH thebean AND
> session.getValue("mybean") set to "this is the bean name"? What I am asking
> is, does the session.getValue return a reference to the object, or is it
> cloning it and creating a seperate object? I can say that in JRun, the two
> different references above DO NOT refer to the same object.
>
> Thanks
>
> -Bruce
>

In Java, variables that are not Java primitive types (like int, long, etc.)
are *always* references to objects (they act basically like pointers in C and
C++).  Thus, session.getValue("mybean") will return a reference to exactly the
same object you originally stored in the session -- it does not create a
clone.

If you are not seeing this behavior, then you are doing something wrong --
probably with how your "session" variable is getting set.  We'll need to see
more of the code to help figure out what's happening.

Craig McClanahan

___________________________________________________________________________
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