Re: explicitly initialising member vars - necessary?
From: VisionSet (spam_at_ntlworld.com)
Date: 10/25/03
- Next message: Gambit: "Re: Frame/Window in other shapes..."
- Previous message: Ben_: "Re: hosting several domain names off J2EE server"
- In reply to: Alex Hunsley: "explicitly initialising member vars - necessary?"
- Next in thread: Michael Borgwardt: "Re: explicitly initialising member vars - necessary?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 25 Oct 2003 14:06:38 +0100
"Alex Hunsley" <alex.hunsley@blueyonder.munge.co.uk> wrote in message
news:o5umb.295$h55.239@news-binary.blueyonder.co.uk...
> A question on "correctness" of java code here....
> I've been lead to believe that declaring class member variables without
> explicitly initialising them (even to null or 0) is a Bad Thing(tm),
> i.e. you should write:
>
> private int count = 0;
>
> and not just
>
> private int count;
>
> However, my understanding of the java spec is that it does specify that
> member variables that aren't explicitly initialised get initialised to 0
> or null. So can anyone give me a good reason to always explicitly
> initialise member vars?
explicit - to show that you really want the attribute to have that value, it
has meaning in your code, you will probably make use of that value, whatever
that value is, even the default eg zero/null.
implicit - the implicit value (eg zero/null) is not meaningful, it is likely
that you will take care of initialisation elsewhere eg in the constructor.
-- Mike W
- Next message: Gambit: "Re: Frame/Window in other shapes..."
- Previous message: Ben_: "Re: hosting several domain names off J2EE server"
- In reply to: Alex Hunsley: "explicitly initialising member vars - necessary?"
- Next in thread: Michael Borgwardt: "Re: explicitly initialising member vars - necessary?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|