Article View: borland.public.jbuilder.java.language
Article #7467Re: How do I change the value of a Boolean
From: dnoyeB
Date: Wed, 20 Jun 2001 18:11
Date: Wed, 20 Jun 2001 18:11
61 lines
2390 bytes
2390 bytes
Wrong question. Any Object passed into a function is just a local reference
the the main object. You can change your "reference pointer" all you want,
but that wont affect the object.
BAsically
change (boolean ok)
{
}
here "ok" is just a pointer to the original Object or primitive. You can
make ok point to something new, but that doesent change the original object.
Believe it or not, this is true for C++ and C as well. They use poionters
to pointers. Thats what you need to do.
You basically have to wrap your object inside an object.
Class Holder
{
public Object var;
}
Change(Holder value)
{
value.var = new Object("new value");
}
That is the ONLY way.
AS you get more familiar with object oriented programming, the need to do
this will disappear.
"Steve Holt" <Steve_Holt@PortaSystems.co.uk> wrote in message
news:3b2a0bc8_2@dnews...
> this doesn't change the value of ok because its passed by value
>
> change(boolean ok)
> {
> ok = true; // only has an effect in this methods scope
> }
>
> So I figured using the Boolean class may achive this because its passed by
> reference
>
> change(Boolean ok)
> {
> // but no method to change value inside the class
> }
>
>
> Please don't ask ne to use the return value as this returns something
else.
> I'm probably going to get it to throw an exception instead but I'm
> interested
> to know how you would do this and why the Boolean class doesn't provide a
> method to change the value - weird if you ask me!
>
>
Technical Details
Message-ID:
<3b30f698$1_2@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:
<3b2a0bc8_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,d64ab128ef10f0b9 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-20 12:33:00 PST From: "dnoyeB" <lamont_gilbert @ rigidsoftware.com> Newsgroups: borland.public.jbuilder.java.language References: <3b2a0bc8_2@dnews> Subject: Re: How do I change the value of a Boolean Date: Wed, 20 Jun 2001 14:11:37 -0400 Lines: 63 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: <3b30f698$1_2@dnews> X-Trace: dnews 993064600 63.68.196.49 (20 Jun 2001 12:16:40 -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