Article View: borland.public.jbuilder.java.language
Article #8587Re: Passing Variables by address/reference, How ?
From: Dave Bird
Date: Fri, 09 Mar 2001 18:34
Date: Fri, 09 Mar 2001 18:34
54 lines
2507 bytes
2507 bytes
In article <984126262.29787.0.nnrp-09.3e31fcf2@news.demon.co.uk>, Wayne
Gibson <wayne.gibson@rendersoft.com> writes
>Hi,
>Was wondering if somebody could help. I converting some routinues over from
>C/C++ to Java, I know that Java doesn't support pointers. So is there a way
>of passing a variable by address/reference to a function ?
This is a tricky question and should be in the FAQ.
In Java, all variables are (?32 bit) words. Either they exist
as the actual values of primitive numeric types such as int.
Or they exist as some sort of "reference" to the location
where a class object or array object is kept.
Hence do not worry about code which looks like....
doSomething(){
int myArray[] = new int[8];
AnObj myObj = new AnObj();
doMore(myArray, myObj);
This will send references to those same original array
and class objects allocated in the calling routine
[not entire copies of everything stored in them].
I'm not sure how to change primitive numeric values
in the calling routine. Try putting them in a class
object:
class FilletVars{
int left=0;
int right=0;
int sideways=0;
FilletVars(){ left=0; right=0; sideways=0; };
};
void fillet(){
FilletVars myBlock = new FilletVars();
shoveit(myBlock);
..........
};
void shoveit(FilletVars oldBlock){
oldBlock.left = 12;
...........
};
--
^-^-^-@@-^-;-^ http://www.xemu.demon.co.uk/
(..)__u news:alt.smoking.mooses
Technical Details
Message-ID:
<yVzOQpBHJSq6EwGn@xemu.demon.co.uk>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!daveReferences:
<984126262.29787.0.nnrp-09.3e31fcf2@news.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,9c851b7595918fce X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-09 17:44:04 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave From: Dave Bird <dave@xemu.demon.co.uk> Newsgroups: borland.public.jbuilder.java.language Subject: Re: Passing Variables by address/reference, How ? Date: Fri, 9 Mar 2001 18:34:47 +0000 Organization: none Message-ID: <yVzOQpBHJSq6EwGn@xemu.demon.co.uk> References: <984126262.29787.0.nnrp-09.3e31fcf2@news.demon.co.uk> NNTP-Posting-Host: xemu.demon.co.uk X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209 X-Trace: news.demon.co.uk 984188530 nnrp-08:17645 NO-IDENT xemu.demon.co.uk:158.152.196.209 X-Complaints-To: abuse@demon.net MIME-Version: 1.0 X-Newsreader: Turnpike Integrated Version 5.00 U <dQumtnY$x4rJ2u5tL5fS$n2vuP> Lines: 54