[666] in java-interest

home help back first fref pref prev next nref lref last post

Re: Java compiler is trying too hard for me

daemon@ATHENA.MIT.EDU (Tientien Li)
Wed Jul 12 17:29:48 1995

From: li@deming.Jpl.Nasa.Gov (Tientien Li)
To: Arthur.Vanhoff@Eng.Sun.COM
Date: Wed, 12 Jul 1995 12:47:46 -0700 (PDT)
Cc: li@deming.Jpl.Nasa.Gov, java-interest@java.sun.com
In-Reply-To: <Roam.1.1.805573507.29204.avh@acorn> from "Arthur van Hoff" at Jul 12, 95 11:25:07 am

Hi Arthur,

>
> You are required to initialize x. Just change the declaration of x
> to "int x = 0;".
>

OK, I think its a good idea to initialize all variables, and I'll do so now.
But why treat local variables differently from instance variables which are
automatically initialized.

see below, pointed out to me by Dan.Evans@peri.com.

> 4.2.1  Instance Variables
> 
> All variables in a class declared outside the scope of a method and not marked
> static (see <A HREF="#17">Static Methods, Variables, and Initializers</A>) are
> instance variables. (Variables declared inside the scope of a method are
> considered local variables.) Instance variables can have modifiers (see
> <A HREF="#23">Modifiers</A>).
> 
> Instance variables can be of any type and can have initializers. If an
> instance variable does not have an initializer, it is initialized to
> zero; boolean variables are initialized to false; and objects are initialized
> to null.
> 
> i.e. it really is initialized to 0.
> 

If the goal is to enforce the initialization of local variables, then why
not check this at the declaration time then at the time variables are used?
It is probably much easier to tell me:

    int x;
        ^ error

instead of tracking all possible references of x, then tell me:

    System.out.println( x );
                        ^ error

--
Tientien Li
li@deming.jpl.nasa.gov
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post