Closure Syntax in Java 8

The expert group for Java 8 have announced the syntax for closures. Thankfully, they have chosen the sane route of choosing a similar syntax to Scala and C#. Quoting from

The decision to choose this syntax was twofold:
– The syntax scores “pretty well” on most subjective measures (though
has cases where it looks bad, just like all the others do). In
particular, it does well with “small” lambdas that are used as method
arguments (a common case), and also does well with large
(multi-statement) lambdas.

– Despite extensive searching, there was no clear winner among the
alternatives (each form had some good aspects and some really not very
good aspects, and there was no form that was clearly better than the
others). So, we felt that it was better to choose something that has
already been shown to work well in the two languages that are most like
Java — C# and Scala — rather than to invent something new.

There is still some argument around fat versus thin arrow (surely a huge issue!) but for those of us that program in multiple languages it’s nice that they haven’t fallen for the “not invented here syndrome” and have chosen something that doesn’t require us to perform massive context switches when using something different.

Leave a Reply

Your email address will not be published. Required fields are marked *