I want to the syntex in Java that passes arguments by reference and by value.
Page 1 of 1
Call-by-reference
#2
Posted 18 May 2005 - 11:12 PM
QUOTE(BAD_BUG @ May 18 2005, 09:58 PM)
um.
Pointers dont exist in java so passing by reference might be troublesome in the sense you might be meaning.
passing by value is easy
Say you have a function, "Blah" for instance and you want to pass it a string by value
You would have the function like so :
CODE
public void Blah(String newvalue)
{
//newvalue contains the passed value
}
To pass something to it you would call it like
CODE
String randomstring = "asdfghjkl";
Blah(randomstring);
Et voila
#3
Posted 19 May 2005 - 03:57 AM
i think java actually passes to methods as a reference?
no point making your program so simple a dummy can use it cause the universe just keeps making a better dummy!
#4
Posted 19 May 2005 - 08:14 AM
I assume that you want to pass a parameter to a method which modifies the parameter's value. There's a good discussion of this at the following web site:
http://www.javapractices.com/Topic37.cjp
This is generally only needed when you need to return more than one value. Otherwise, make the method return type the object that is created/modified by the method.
http://www.javapractices.com/Topic37.cjp
This is generally only needed when you need to return more than one value. Otherwise, make the method return type the object that is created/modified by the method.
#6
Posted 23 May 2005 - 01:04 PM
Note that String objects aren't passed by reference but copied instead.
-Xinox Software
-Xinox Software
Share this topic:
Page 1 of 1

Help










