Tuesday, June 1, 2010

Java's hot new syntax for closures



Quick, what does #()(3).() do? OK, I think one can get used to it.

But "support references to ‘this’" sounds really doomed. A closure simply has nothing to do with a "current object". One day, all languages will have methods outside classes, and then the whole "implicit this" charade, both in methods and lambdas, will be clearly viewed as an embarrassing historical accident with huge costs in wasted brainpower. (It's also one of JavaScript's dumbest parts.)

(Also, that they have to make a difference between "statement lambdas" and "expression lambdas" again shows the havoc wreaked by the completely superfluous and annoying distinction between statements and expressions.)

2 comments:

Wim Coenen said...

If the context of the closure supports references to "this", then you should also be able to reference "this" inside the closure.

Why? Because the definition of closure implies it. A closure is more than just an anonymous method.

Manuel Simoni said...

Yeah, but my point is that "this" shouldn't be in the context in the first place.

If the language has an implicit "this", as does Java, then maybe you're right.