PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed Need Money Easy and Quick?

Re: Pointers in Java: Was Re: Strings...immutable?

 List
Subject: Re: Pointers in Java: Was Re: Strings...immutable?
Poster: JTjt_printer_dude@yahoo.ca
Date: Fri, 23 Mar 2007 23:15:57 GMT
Related Postings: 1 2 3 4 5 6 7
Lew wrote:
> Wojtek wrote:
>> Chris Uppal wrote :
>>> Wojtek wrote:
>>>
>>>> No it is a call by reference. If it was a call by value, then a clone
>>>> of the StringBuffer (in the following code) would be placed in the
>>>> stack. The method would then use the clone and the calling main() would
>>>> still use its private copy.
>>>
>>> So, taking the two points together, most Java programmers prefer to
>>> stick very tightly to the low-level view of parameter passing and
>>> state that Java /only/ has call by value, but that some of those
>>> values are references to objects. Anything else is known to lead to
>>> massive confusion.
>
> When I read SCJP study materials, they have always asserted
> unequivocally "call-by-value" as the only correct answer to "how does
> Java pass method arguments?"
>
> -- Lew Practical Java Programming Guide Peter Haggar Praxis 1: Understand that parameters are passed by value, not by reference

import java.awt.Point; public class PassByValue { public static void modifyPoint(Point pt, int j){ pt.setLocation(5,5); j=15; System.out.println("During modifyPoint " + "pt = " + pt t " and j = " + j); } public static void main(String [] args) { Point p = new Point(0,0); int i = 10; System.out.println("Before modifyPoint " + "p = " + p + " and i = " + i); modifyPoint(p, i); System.out.println("After modifyPoint " + "p = " + p + " and i = " + i); } }

 

Page2Go2.com is not responsible for content of this message.