🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19698

Re: passing parameters to methods to get a value back (by reference in C++) and one other question

#19698
From: Eric Nagler
Date: Fri, 02 Jan 1998 00:00
42 lines
1512 bytes
You can't do that. Integer objects are immutable. The best Java can do
is create a new instance using the modifed value. For example:

// C++
void modify(int& data)
{
   ++data;
}
// ...
int main()
{
  int value = 1;
  modify(value);
}

// Java
Integer modify(Integer data)
{
  return new Integer(++data.intValue());
}
// ....
   Integer answer = modify(new Integer(1));

On Tue, 30 Dec 1997 21:24:38 GMT, ait@concentric.net (Jeff Kish)
wrote:

>Sorry for my vagueness...
>In C++ I can do:
>
>routine(int & modifedByRoutine) {modifiedByRoutine = 6;} // pretend 
>\\ this is a method, not a stand alone function
>
>main()
>{
>int someInt = 2;
>  routine(someInt);
>// someInt equals 6 now
>}
>
>Now, how to do this in Java, i.e. make the parameters return something
>"changed" to the calling environment
Technical Details
Message-ID: <34ae6a6e.24478849@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <34a9282d.69646145@forums.borland.com> <34a9583d.11419067@forums.borland.com> <34aa6612.85491420@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,90bf066ce13115b3
X-Google-Attributes: gidf74b3,public
From: 76711.521@compuserve.com (Eric Nagler)
Subject: Re: passing parameters to methods to get a value back (by reference in C++) and one other question
Date: 1998/01/02
Message-ID: <34ae6a6e.24478849@forums.borland.com>
X-Deja-AN: 312241390
Content-Transfer-Encoding: 7bit
References: <34a9282d.69646145@forums.borland.com> <34a9583d.11419067@forums.borland.com> <34aa6612.85491420@forums.borland.com>
Content-Type: text/plain; charset=us-ascii
Organization: TeamB
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language