Semantics--he's quibbling with you about semantics. In Java, some people don't like to call it "passing by references." In certain quarters, they'll boo you down & not let you finish your sentence, if you use that term.
(Despite the references someone quoted, I can think of a few other books that unabashedly call it passing by reference. But in any case, "appeal to authority" is a weak argument.) It says something about the confusion this causes, that you, who got the official terminology wrong, are the only one who got the answer right! --- Nathan Tenney <[EMAIL PROTECTED]> wrote: > Perhaps I am wrong, but I understood passing a > reference to an object to be termed pass by > reference... > > --- Tom Jordan <[EMAIL PROTECTED]> wrote: > > Nathan, > > > > You are description of the "fillMe" argument and > the > > effect of the "fill()" > > method is correct, but your assertion that "Java > > does use pass by reference" > > is WRONG. > > > > The following statement is absolutely true: "Java > > passes all arguments by > > VALUE" (references listed below). > > > > When passing an Object it is the object reference > > that gets passed (not the > > object itself) and it is passed by value. In other > > words, a copy of the > > object reference is passed to the method. As you > > correctly stated, this > > reference points the orginal object and can be > used > > to modify the orginal > > object thru its public mutator methods. > > > > Tom > > > > References: > > "Exploring Java" 2nd edition, O'Reilly, Pg 143 > > "Argument Passing and > > References" > > "Java 2 Certification Study Guide", Sybex, Pg 17 > > "Argument Passing" > > > > > > > > -----Original Message----- > > From: Nathan Tenney [mailto:[EMAIL PROTECTED]] > > Sent: Friday, May 31, 2002 12:36 PM > > To: JDJList > > Subject: [jdjlist] Re: Java : pass by reference??? > > > > > > Ok, I didn't take the time to read all the > messages > > in > > this thread, so someone may have already answered > > this > > to my satisfaction, but the 4 or 5 I did read had > it > > totally wrong. > > > > Java does use pass by reference. Think of the > > variable fillMe in your fill methods has holding a > > reference to another object. At the beginning of > > the > > method, it refers to the object you passed in when > > you > > called fill. However, when you used new, you > > changed > > which object fillMe refers to, so any changes made > > to > > fillMe at this point will not touch the original > > object fillMe referred to. NOTE: defining a > String > > explicitly (with "") is the same thing as using > new. > > > > The major problem with your example is that you > used > > immutable objects (String and Integer) as the > > objects > > to refer to. Immutable Objects are those that > have > > no > > methods for modifying the data that is stored in > > them. > > All you can do with them is create new Objects. > > Try > > this example with StringBuffer instead of String, > > and > > replace fillMe = "test"; with fillMe.append(" > > test"); > > and you will see a difference in your output. > > > > Hope that was easy to understand. > > > > --- H Shankaranarayanan <[EMAIL PROTECTED]> > > wrote: > > > class test > > > { > > > /** > > > * Description of the Method > > > * > > > *@param fillMe Description of the > Parameter > > > */ > > > public void fill(String fillMe) > > > { > > > fillMe = "test"; > > > } > > > > > > > > > /** > > > * Description of the Method > > > * > > > *@param fillMe Description of the > Parameter > > > */ > > > public void fill(Integer fillMe) > > > { > > > fillMe = new Integer(100); > > > } > > > > > > > > > /** > > > * Description of the Method > > > * > > > *@param args Description of the Parameter > > > */ > > > public static void main(String args[]) > > > { > > > > > > try > > > { > > > test objTest = new test(); > > > String testfill = new > String("main"); > > > objTest.fill(testfill); > > > System.out.println("Fill me result:" > + > > > testfill); > > > > > > Integer intFill = new Integer(200); > > > objTest.fill(intFill); > > > System.out.println("Fill me result:" > + > > > intFill); > > > > > > } catch (Exception e) > > > { > > > e.printStackTrace(); > > > } > > > } > > > } > > > > > > > > > That is a sample program i wrote to test this > > fact. > > > The result is dependent > > > on scope of the variable. > > > So wots this pass by reference concept that > every > > > text book around the world > > > states about Java. > > > > > > How does the pass by reference concept work > > anyways? > > > > > > I might have missed something here. If i did i > > would > > > appreciate if anyone > > > told me wot is it that i did miss. > > > > > > I was expecting this program to work otherwise > but > > > it does not. > > > > > > --Shankar > > > > > > > > > To change your membership options, refer to: > > > http://www.sys-con.com/java/list.cfm > > > > > > ===== > > ---------------------------------- > > Nathan Tenney > > Alumni Utah State University > > [EMAIL PROTECTED] > > ---------------------------------- > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! - Official partner of 2002 FIFA World Cup > > http://fifaworldcup.yahoo.com > > > > To change your membership options, refer to: > > http://www.sys-con.com/java/list.cfm > > > > > > THIS TRANSMISSION, INCLUDING ANY ATTACHMENTS OR > > FILES, > > CONTAINS AIRNET COMMUNICATIONS CORPORATION > > CONFIDENTIAL > > AND PROPRIETARY INFORMATION WHICH MAY BE OTHERWISE > > EXEMPT > === message truncated === __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
