Patricia Shanahan <pats@acm.org> wrote or quoted in
Message-ID: <t755h.4869$l25.4327@newsread4.news.pas.earthlink.net>:
Knute Johnson wrote:
...
for (Enumeration<Integer> e=hash.keys(); e.hasMoreElements();)
String[] array = hash.get(e.nextElement()); // <---- error
...
You are confusing two very different entities, a statement and a
variable declaration.
The for MUST be followed by a statement.
You have a local variable declaration, which is not itself a statement
but can appear in a compound statement, such as a brace-enclosed block.
Incidentally, it seems a bit pointless because you assign to array and
then immediately leave its scope of declaration.
#0: "for ( ... ) a declaration statement;"
For a moment, let's consider the above '#0' not to be an error.
Now,
Let's take all possible cases into account.
Case 1)
#1_e:
for (...) int i = 0;
#1_c:
for (...) { int i = 0; }
Both '#1_e' and '#1_c' are useless because 'i' is never
read and '0' is constant.
Case 2)
#2_e:
for (...) int i = parse(...);
#2_c:
for (...) { int i = parse(...); }
Both '#2_e' and '#2_c' are not useless because 'parse(...)'
can change the state of some instances (ex: fields).
Case 3)
#3_e:
for (...) parse(...);
#3_c:
for (...) { parse(...); }
Both '#3_e' and '#3_c' are not useless.
From this point of view, '#*_e' are equivalent to '#*_c' .
But,
'#*_e' are errors and '#*_c' do not.
Is it valid that '#*_c' do not be errors ?
If so, what is the advantage of it ?
"Type name = ... ;" is composed of more than one statements
like a brace-enclosed block.
I think that it is unartificial that a compiler give warnings
about '#*_e', not errors.
The Java(tm) language is what it is and it ain't what it ain't.