----Original Message-----
From: Madhav Vodnala [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 3:59 PM
To: JDJList
Subject: [jdjlist] Re: Java : pass by reference???

Hi Shankar
 
Here is my take on 'pass by reference' theory.
 
Here are the absolute statements about 'pass by reference'
 
    1)  Pass by reference works for all Classes, except Strings and arrays.
[Shankar] Pass by reference works for all objects(incl arrays which are also objects
be it even primitive arrays.as by definition anything on the heap is an object and anything "new"ed
is on the heap)  And by inlining the code in the methods that am calling am
able to change the value of the variables or objects to be precise. So why not from
inside a method?

SO, the theory is
 
If you assign the new object (created with new ) to the function argument (which refers to the calling method variable) and modify its
content, it doesnt modify the calling method's variable value, irrespective of whether calling method's variable is passed by value or passed by
reference.
[Shankar] this is wot i infered from the behaviour of the code So then coming back to the "pass by reference"
for objects. This behaviour says its a "pass by value" and "pass by reference" correct?
 
Another interesting fact is a swap method (like the one u write in C to swap an integer value)
cannot be written in Java just for this one small behavioural issue of the language. I dont know
if its an issue for starters. u cant just swap two strings inside a called method cos of this.
 
-Madhav
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to