Article View: borland.public.jbuilder.java.language
Article #7263Re: can i change a int type Not Integer type argument in a function ?
From: dnoyeB
Date: Thu, 28 Jun 2001 18:38
Date: Thu, 28 Jun 2001 18:38
31 lines
1779 bytes
1779 bytes
No you can not alter objects within functions. AS in C and C++, passing a
primitive OR object into a function always copies. If its a primitive, you
get a copied primitive, if its an object, you get a copied reference.
Changing the copy does not affect the original.
That way you never have to worry about passing around your references and
getting them back null. Again, the only context a value can be set to null
is the context in which it was created.
"wallance" <wallance@sh.ctil.com> wrote in message news:3b3b1371_2@dnews...
> hi,
> i want to change a int type argument in java,what should i do?
> for example:
>
> public func1(){
>
> int i = 10;
> func2(i);
> System.out.println(i) ===> 11
>
> }
> public func2(int arg){
> arg = arg + 1;
> }
>
> i know in java your can trans a object .then it can modify by reference.
> but this is int type,not object.what should i do?
>
>
Technical Details
Message-ID:
<3b3b7ae2_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3b3b1371_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,9b3cb30cd9a02399 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-28 11:46:55 PST From: "dnoyeB" <lamont_gilbert @ rigidsoftware.com> Newsgroups: borland.public.jbuilder.java.language References: <3b3b1371_2@dnews> Subject: Re: can i change a int type Not Integer type argument in a function ? Date: Thu, 28 Jun 2001 14:38:39 -0400 Lines: 33 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 63.68.196.49 Message-ID: <3b3b7ae2_1@dnews> X-Trace: dnews 993753826 63.68.196.49 (28 Jun 2001 11:43:46 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews