Article View: borland.public.jbuilder.java.language
Article #19709Re: passing parameters to methods to get a value back (by reference in C++) and one other question
From: Joe Nuxoll
Date: Mon, 05 Jan 1998 00:00
Date: Mon, 05 Jan 1998 00:00
28 lines
1301 bytes
1301 bytes
Eric Nagler wrote:
> 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:
True, but you can do it if you use a regular mutable class like Point or
Rectangle or your own class like AnInteger:
public class AnInteger {
public int value;
public AnInteger() {}
public AnInteger(int value) { this.value = value; }
}
...
void increment(AnInteger data) {
data.value += 1;
}
...
void main() {
AnInteger i = new AnInteger(5);
increment(i);
}
- Joe Nuxoll
Technical Details
Message-ID:
<34B1531A.3C9548B6@corp.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<34a9282d.69646145@forums.borland.com> <34a9583d.11419067@forums.borland.com> <34aa6612.85491420@forums.borland.com> <34ae6a6e.24478849@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: Joe Nuxoll <jnuxoll@corp.borland.com> Subject: Re: passing parameters to methods to get a value back (by reference in C++) and one other question Date: 1998/01/05 Message-ID: <34B1531A.3C9548B6@corp.borland.com> X-Deja-AN: 313072726 Content-Transfer-Encoding: 7bit References: <34a9282d.69646145@forums.borland.com> <34a9583d.11419067@forums.borland.com> <34aa6612.85491420@forums.borland.com> <34ae6a6e.24478849@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: Borland International, Inc. Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language