JCreator Forum Board: Call-by-reference - JCreator Forum Board

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Call-by-reference

#1 User is offline   BAD_BUG 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 18-May 05

Posted 18 May 2005 - 09:58 PM

I want to the syntex in Java that passes arguments by reference and by value.
0

#2 User is offline   Phil^ 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 175
  • Joined: 19-March 05

Posted 18 May 2005 - 11:12 PM

QUOTE(BAD_BUG @ May 18 2005, 09:58 PM)
I want to the syntex in Java that passes arguments by reference and by value.
View Post


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
0

#3 User is offline   jeef 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 344
  • Joined: 20-March 05
  • Location:New Zealand

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!
0

#4 User is offline   kiwipete 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 13-May 05

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.
0

#5 User is offline   bradleysmith 

  • Member
  • PipPip
  • Group: Members
  • Posts: 18
  • Joined: 16-March 05

Posted 23 May 2005 - 12:40 PM

Everything is passed by reference in Java. Except primitives.

0

#6 User is offline   xinox 

  • Administrator
  • Group: Admin
  • Posts: 482
  • Joined: 09-March 05

Posted 23 May 2005 - 01:04 PM

Note that String objects aren't passed by reference but copied instead.

-Xinox Software


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic