🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#19524
From: Brian Burton
Date: Mon, 19 Jan 1998 00:00
49 lines
2101 bytes
Except of course that you would never make "value" public.  You would instead
use a setValue() method so that you could later make it synchronized or apply
some other change without breaking programs that use AnInteger.

public class AnInteger {
  private int value;
  public AnInteger() {}
  public AnInteger(int value) { this.value = value; }
  public int getValue() { return value; }
  public void setValue(int new_value) { value = new_value; }
}

++Brian

Joe Nuxoll wrote:
> 
> 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

-- 
Brian Burton                        Custom Software Development
Burton Computer Corporation         Java, C++, Orbix, Tuxedo
http://www.burton-computer.com      OO Consulting and Mentoring
Technical Details
Message-ID: <34C3F593.D8E12239@burton-computer.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> <34ae6a6e.24478849@forums.borland.com> <34B1531A.3C9548B6@corp.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: Brian Burton <brian.burton@burton-computer.com>
Subject: Re: passing parameters to methods to get a value back (by reference in C++) and one other question
Date: 1998/01/19
Message-ID: <34C3F593.D8E12239@burton-computer.com>
X-Deja-AN: 317514515
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> <34B1531A.3C9548B6@corp.borland.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: Burton Computer Corporation
Newsgroups: borland.public.jbuilder.java.language