
13 Jan
2010
13 Jan
'10
6:53 p.m.
Anonymous classes in Java close over their lexical environment (can refer to variables in that lexical environment, with values bound at the time of instance construction) with the caveat that only local variables/parameters marked as 'final' may be referred to. Aside from the horrible syntax, this is the key distinction between them, and, say, Ruby closures. Referring to mutable variables from inside a closure has its drawbacks, making the horrible syntax the biggest stumbling block to using them IMHO (other than runtime overhead, which I believe is also an issue).
Yes, this. Which makes them basically unusable where you might want proper closures.