Results 1 to 2 of 2
- 10-19-2009, 04:40 PM #1Member
- Join Date
- Oct 2009
- Rep Power
- 10-19-2009, 04:45 PM #2
Everything in Java is passed "by value". Everything.
- When an argument is passed to a function, the invoked function gets a copy of the original value.
- The local variable inside the method declaration is not connected to the caller's argument; any changes made to the values of the local variables inside the body of the method will have no effect on the values of the arguments in the method call.
- If the copied value in the local variable happens to be a reference (or "pointer") to an object, the variable can be used to modify the object to which the reference points.
Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory.... The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
-- James Gosling, et al., The Java Programming Language, 4th Edition
http://www.javaranch.com/campfire/StoryPassBy.jspMath problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- By katie in forum New To JavaReplies: 2Last Post: 10-19-2009, 04:45 PM
- By kellykellykelly in forum Advanced JavaReplies: 1Last Post: 02-28-2009, 08:59 AM
- By ajith_raj in forum Advanced JavaReplies: 4Last Post: 02-12-2009, 12:46 PM
- By raj reddy in forum Advanced JavaReplies: 1Last Post: 04-15-2008, 01:09 PM
- By Deathmonger in forum New To JavaReplies: 2Last Post: 03-12-2008, 03:51 PM