Re: Changing the value of Boolean?
From: xarax (xarax_at_email.com)
Date: 02/20/04
- Next message: Scott Ellsworth: "Re: Ant API - Examples where? Please help."
- Previous message: David Zimmerman: "Re: Strange spaces when using BufferedReader"
- In reply to: Christophe Vanfleteren: "Re: Changing the value of Boolean?"
- Next in thread: Steve W. Jackson: "Re: Changing the value of Boolean?"
- Reply: Steve W. Jackson: "Re: Changing the value of Boolean?"
- Reply: Dale King: "Re: Changing the value of Boolean?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 20 Feb 2004 19:16:14 GMT
"Christophe Vanfleteren" <c.v4nfl3t3r3n@pandora.be> wrote in message
news:E6qZb.7848$Ai1.445545@phobos.telenet-ops.be...
> Blueyonder wrote:
>
> > Sure I've read somewhere (but can't find it now) that you cannot change
> > the value of a Boolean tyep variable. You have to set it each time like
> > this -
> >
> > ////////////////////////////////////////////////////////////
> > Boolean b = new Boolean(true);
> >
> > b = new Boolean(false);
> > ////////////////////////////////////////////////////////////
> >
> > Is this correct?
> >
> > thanks
> >
> > harry
>
> Yes, once a Boolean is created, it's value can not be changed (as is the
> case with all "wrapper" types, such as Integer, Long, ...). We call such
> classes immutable.
>
> But in the case of boolean, instead of creating a new Boolean using
> something like "new Boolean(false)", use the Boolean b = Boolean.FALSE
> instead.
>
> It prevents having to create an extra Boolean object, which would behave
> exactly the same as new Boolean(false) anyway.
>
> --
> Kind regards,
> Christophe Vanfleteren
Exactly right. A simple idiom is:
{
boolean bool = methodThatReturnsPrimitiveBoolean();
Boolean theBoolean;
/* Translate boolean primitive to Boolean instance. */
theBoolean = (bool ? Boolean.TRUE : Boolean.FALSE);
}
- Next message: Scott Ellsworth: "Re: Ant API - Examples where? Please help."
- Previous message: David Zimmerman: "Re: Strange spaces when using BufferedReader"
- In reply to: Christophe Vanfleteren: "Re: Changing the value of Boolean?"
- Next in thread: Steve W. Jackson: "Re: Changing the value of Boolean?"
- Reply: Steve W. Jackson: "Re: Changing the value of Boolean?"
- Reply: Dale King: "Re: Changing the value of Boolean?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|