View Single Post
Old May 23rd, 2006, 1:53 PM   #14
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 903
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Quote:
Originally Posted by NSchnarr
Objects on the other hand point to there values(referenced),
so if you have
obj x = 'ex1', obj y='ex2'
x = y (this makes them point to the same place in memory)
x = 'ex2', y = 'ex2'
Any change made to one, changes the other.
x = 'ex1'
x = 'ex1' y = 'ex1'
This is incorrect.

In your example, x = y makes x and y point to the same object in memory, not the same place in memory. In additon, setting one of the variables to a new object will not affect the other as they no longer point to the same object in memory.

Any changes made to the object that both x and y are pointing to after assigning x = y will be reflected in both variables (for example, x.setAttribute(newvalue)), but reassigning one of the variables to another object (for example, x = new Object()) will not affect the other.

You would benefit from reading the article I referred to in a previous post, Java is Pass-By-Value, Dammit!.
titaniumdecoy is offline   Reply With Quote