From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,803df5f3f60558d5 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Uninitialized variables, Java example Date: 1996/07/25 Message-ID: #1/1 X-Deja-AN: 171349732 references: <31EEACDA.64880EEB@sage.inel.gov> <4t3f1u$t0u@newsbf02.news.aol.com> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-25T00:00:00+00:00 List-Id: In article , Arra Avakian wrote: >The language spec says the following about this subject: > > 4.2.3 Setting Local Variables > > Methods are rigorously checked to be sure that all local variables > (variables declared inside a method) are set before they are > referenced. Using a local variable before it is initialized is a > compile-time error. That's not a language spec, IMHO. That's a vague description that might be useful to a person learning Java, but it doesn't tell me exactly which programs are disallowed at compile time. Is this feature of Java precisely defined somewhere (other than in the Java implementation(s))? The last sentence doesn't say which cases are compile-time errors, despite the fact that they do NOT use uninit vars. The halting theorem tells us that there MUST be some such cases. And understanding which cases those are is crucial to deciding whether this is a good rule. Also, note that this rule explicitly applies to local variables of a method. It does not apply to global variables, and it does not apply to components of objects. If I remember correctly, Java automatically initializes those to (null, False, zero, whatever), depending on the type. But I could be misremembering my Java. - Bob