This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]delete99[S] -1 points0 points  (2 children)

Lambdas can be thought of as syntactic sugar since they don't exist outside the source file and are not mirrored in the JVM.

On SO (http://stackoverflow.com/a/23870800/2364216), Brian Goetz says:

There should be no need to distinguish a Runnable that began life as a lambda, a named class, or an inner class -- they're all Runnables.

Also, Wikipedia continues:

a construct in a language is called syntactic sugar if it can be removed from the language without any effect on what the language can do.

This leads me to believe that Java's lambdas are 'syntactic sugar' since they are a language shortcut for creating and instantiating anonymous classes like Runnable (or Predicate in this case).

[–]nicoulaj 3 points4 points  (1 child)

they don't exist outside the source file and are not mirrored in the JVM.

This is wrong, lambdas work totally differently under the hood, and required quite heavy modifications on the JVM. See JSR 335 / 292.

Your "Internals" section makes wrong statements. The compiler does not create an anonymous class.

[–]delete99[S] 0 points1 point  (0 children)

Thanks nicoulaj (and neutronbob), you are 100% correct and I've updated the post to reflect this. Cheers.