Effectively final effective?
Alex Blewitt
alex.blewitt at gmail.com
Sat Feb 27 14:35:11 PST 2010
On 27 Feb 2010, at 22:24, Reinier Zwitserloot wrote:
> I don't understand. There is no source incompatibility.
>
> That is, it is perfectly allright for a new language feature to make previously illegal code, legal. For example, this:
>
> for (String x : foo) {}
>
> was illegal in java 1.4. It was legal in 1.5.
That would have been syntactically incorrect in Java 1.4. However, it is not a syntax error to omit a final keyword from a variable captured by an inner class, but a semantic one. The point is that effectively final may result in code being developed outside of new language (syntax) features be semantically incorrect on earlier versions.
One could argue that the same is also true of e.g. String.split or other new features (which then fail to compile on older versions of code), so it's in this class of error. However, I wanted to raise the observation that the effective finalness, as applied to inner classes, may result in code which is compatible with 1.7 but not 1.6, even if it doesn't touch any new syntax features like the one you highlighted.
Alex
More information about the lambda-dev
mailing list