3 ms·
Yes, spot on. For your original code example, the Java compiler would have failed with an error that the variable 'i' was not declared final (immutable). Java
by RyanZAG 13y ago
Yes, spot on.
For your original code example, the Java compiler would have failed with an error that the variable 'i' was not declared final (immutable). Java 8 supports lambdas now, but in earlier Java versions you would have had to add a line like 'final int fi = i;' and you could then have used the fi inside the closure. The point in my previous post that the compiler detecting this ambiguity is exceptionally helpful and I'd prefer more languages to follow that route.
With Java 8 lambdas, it's much the same but with some nice syntax to make it easier[1].
[1] http://java.amitph.com/2012/08/at-first-sight-with-closures-in-java.html http://java.amitph.com/2012/08/at-first-sight-with-closures-...
- christian_fei 13y agonever got that much into Java though