This is a general comment on the thread rather than a specific
response to Roedy...
I'm intrigued by the general tone of the responses: this is a bit of a
quirk in Java and you just have to live with it. For me the rules of
-- and philosophy behind -- definite assignment are what makes Java a
language I like to program in and a real step forward from
predecessors like C and Fortran.
Why do I feel this way?
We always talk about Java as being portable. However C and Fortran
and C++ and all are also very portable so long as they are used
properly. Good Fortran will run beautifully on a much larger range of
platforms than Java can aspire to. However I don't always write
perfect programs. Every once in a while
)) I write a bug. The
consequences in C and Fortran may be large or small, but critically
they are very likely to be undefined and vary substantially from
implementation to implementation.
Java is the first language that I've worked in extensively which
really supports the philosophy that it is as helpful when programs
fail consistently when they are wrong as that they work consistently
when they are correct. Consequently Java has a much more precise view
of what constitutes a correct program and what is not. This precision
comes at the cost of a bit of seeming arbitrariness in the treatment
of
uninitialized variables, but the rules are pretty clear and far better
than leaving it to the compiler to decide if it can prove that a
variable is set.
Nothing's perfect, but I submit that Java's seemingly arbitrary rules
for definite assignment are a step in that direction.
Regards,
Tom McGlynn