1. Primitives are passed by value 2. Objects (references) are passed by passing a copy of the reference (Not the actual reference !!! and hence only state changes on the copy will be reflected with the original reference)
Originally posted by Nischal Tanna: Not really.....
1. Primitives are passed by value 2. Objects (references) are passed by passing a copy of the reference (Not the actual reference !!! and hence only state changes on the copy will be reflected with the original reference)
Java passes object references by value. Thus while you can change the content of the referenced object you cannot change the reference (and thus replace the object with another one).
That's pass by value.
42
Nischal Tanna
Ranch Hand
Joined: Aug 19, 2003
Posts: 182
posted
0
Originally posted by Jeroen Wenting:
Java passes object references by value. Thus while you can change the content of the referenced object you cannot change the reference (and thus replace the object with another one).
That's pass by value.
Ok Ok... Obviously literally it is called pass by value ... where did i deny it?... but i wanted to explain technically rather than putting exact grammar
Dibbo Khan
Ranch Hand
Joined: Dec 19, 2004
Posts: 147
posted
0
Java passes object references by value,
Isn't that a meaningless answer, it will confuse the issue, you are still ultimately pointing to a reference on the managed heap if you are dealing with an object instead of a primitive type.
MCPD (Enterprise Application Developer, Windows Developer, Web Developer - .NET 2.0), MCTS (Windows Apps, Web Apps and Disbributed Applications - .NET 2.0), MCITP (Database Developer & Business Intelligence Developer - SQL Server 2005), MCAD, MSCD.net, SCJP 5, SCWCD 1.4, SCBCD, SCMAD, SCDJWS, SCJA
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
Java passes object references by value,
Isn't that a meaningless answer, it will confuse the issue...
Originally posted by Dibbo Khan: Java passes object references by value,
Isn't that a meaningless answer, it will confuse the issue, you are still ultimately pointing to a reference on the managed heap if you are dealing with an object instead of a primitive type.
No. What is passed is the reference, not the object. Many people forget that, and then get highly frustrated when they try to do something like
and 1 is printed. If objects were passed by value as they expect 2 would be printed instead.
Timmy Marks
Ranch Hand
Joined: Dec 01, 2003
Posts: 226
posted
0
btw, a search of this forum with the words "Java Pass Value Reference" has 81 hits! The same search in Java in General (Beginner) resulted in 40 more! In 3 minutes, I found over 100 answers to this question on this board! Did we really need another one? [ June 08, 2005: Message edited by: Timmy Marks ]