Any idea why this compiles in Java 5 but not in Java 6?
for(final int k=0; k<10; k++);
What's the logic behind this? Any change to the scope of the variables between Java 5 and 6?
I cannot find anything in Sun documentations regarding this.
Any idea why this compiles in Java 5 but not in Java 6?
for(final int k=0; k<10; k++);
What's the logic behind this? Any change to the scope of the variables between Java 5 and 6?
I cannot find anything in Sun documentations regarding this.
For me it doesn't compile either with Java 6 or Java 1.3.1. (I don't have easy access to other versions.)
I very much doubt it would compile with any "normal" version of javac - the k++ part of the loop is invalid as k is declared final.
Are you sure you got it to compile under Java 5? Which exact version, on what platform? Were you using an IDE, or was it from the command line?
It shouldn't compile in any version of Java, because of the k++.
Are you sure you didn't get it mixed up with the for-each loop? Because the following does compile in Java 5 and up:
for (final int k : someIntArray) { ... }