Article View: borland.public.jbuilder.java.language
Article #7274Re: can i change a int type Not Integer type argument in a function ?
From: CLG
Date: Fri, 29 Jun 2001 03:25
Date: Fri, 29 Jun 2001 03:25
74 lines
2929 bytes
2929 bytes
Java always passes by reference.
However, you can only manipulate the references you have. Within the
function call, you do not have the original reference, you have a copy of
it. Therefore you can't change the original reference.
Simple answer is NO.
--
Peace,
Carl L. Gilbert
lamont_gilbert @ rigidsoftware.com
http://www.rigidsoftware.com
ICQ 614395-currently stolen working to retrieve.
"Then said I, Wisdom [is] better than strength: nevertheless the poor man's
wisdom [is] despised, and his words are not heard." Ecclesiastes 9:16
"wallance" <wallance@sh.ctil.com> wrote in message news:3b3bda1e_2@dnews...
> my question is can i use "PASS BY Reference" not "pass by value" in java'f
> function call?
> like in c++ ,you can use void func(char &arg).
>
> "dnoyeB" <lamont_gilbert @ rigidsoftware.com> wrote in message
> news:3b3b7ae2_1@dnews...
> > 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:
<3b3bf625$1_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3b3b1371_2@dnews> <3b3b7ae2_1@dnews> <3b3bda1e_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 20:39:07 PST From: "CLG" <lamont_gilbert @ rigidsoftware.com> Newsgroups: borland.public.jbuilder.java.language References: <3b3b1371_2@dnews> <3b3b7ae2_1@dnews> <3b3bda1e_2@dnews> Subject: Re: can i change a int type Not Integer type argument in a function ? Date: Thu, 28 Jun 2001 23:25:17 -0400 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 24.181.226.14 Message-ID: <3b3bf625$1_1@dnews> X-Trace: dnews 993785381 24.181.226.14 (28 Jun 2001 20:29:41 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews