🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: changing reference in a method

#7504
From: Joi Ellis [TeamB]
Date: Sun, 17 Jun 2001 16:11
33 lines
1977 bytes
Ivan Trotter <ivan@admiraluno.com> wrote:
> Hi

> I have this source:
> public class MyObject{
>    public void SomeMethod(Object anObject);
>           ....
>           anObject=null;
>    }



> When I call this method, the anObject in params pass referenced, this means
> that I can access the content of anObject in SomeMethod, after that I try to
> change the reference:  anObject = null,  and only changes in the method, but
> when steps over the method  the reference become the same just before the
> method call.

> How can I assign null to the reference without returning some value in the
> method?

You can't.  Java is pass by reference and you can't change the original
object that the method recieved.  You can, however, change member fields
on that object.  

Create a holder object, stored anObject in a field on the holder, then pass
in the holder object.

-- 
Joi Ellis (TeamB)               http://www.teamb.com/
No direct email, please.
For best results, post on news server newsgroups.borland.com!
Newsgroup Info: http://www.borland.com/newsgroups/guide.html
Technical Details
Message-ID: <3b2cd6b8_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsgate.cistron.nl!newsfeeds.belnet.be!news.belnet.be!news1.ebone.net!news.ebone.net!newsfeed.freenet.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews!not-for-mail
References: <3b2ccfc1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,de239f43bd446264
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-17 09:31:55 PST
Message-ID: <3b2cd6b8_2@dnews>
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: changing reference in a method
Newsgroups: borland.public.jbuilder.java.language
References: <3b2ccfc1_1@dnews>
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.16-3 (i686))
NNTP-Posting-Host: 209.46.41.66
Date: 17 Jun 2001 09:11:36 -0700
X-Trace: dnews 992794296 209.46.41.66 (17 Jun 2001 09:11:36 -0700)
Lines: 33
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!newsgate.cistron.nl!newsfeeds.belnet.be!news.belnet.be!news1.ebone.net!news.ebone.net!newsfeed.freenet.de!news1.dtag.de!news.stgl.sel.alcatel.de!news.stgl.sel.alcatel.de!dnews!not-for-mail