Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Lambda expressions [closed]

Lambda expressions are being added in Java 8. I want to understand why this is important. What does it mean to a Java programmer who is yet to be exposed to functional programming idioms? Does it mean I can write code that performs better or scales massively or does it only make the code less verbose. Or all of it.

like image 255
The_301 Avatar asked May 31 '13 14:05

The_301


People also ask

Are Java lambdas closures?

Java supports lambda expressions but not the Closures. A lambda expression is an anonymous function and can be defined as a parameter.

Are lambda functions closures?

Lambda functions may be implemented as closures, but they are not closures themselves. This really depends on the context in which you use your application and the environment. When you are creating a lambda function that uses non-local variables, it must be implemented as a closure.

Are there closures in Java?

Java does not have closures. if you then do something like pass f to a function, scope is the scope of where it was defined.

Does Java 8 support closures?

In effect, java doesn't have closures at all. One may not notice the difference unless they have used real closures in a language that actually supports them.


1 Answers

Oracle already has tutorial up on the topic. It lists several great uses cases.

Before I found the link, I was going to say that lambda expressions let you pass "functions" to code. So you can write code more easily that we used to need a whole mess of interfaces/abstract classes for. For example, suppose you have code that has some complex loop/conditional logic or workflow. At one step you want to do something different. With lambda expressions, you can just pass in that "something different." Read the tutorial though. It's very clear.

like image 156
Jeanne Boyarsky Avatar answered Oct 05 '22 15:10

Jeanne Boyarsky