daniele licitra wrote:
Cay Horstmann wrote:It's just a function without a name.
So, Java8 don't introduce something like functional programming?
In languages like Scheme or Haskell, you can define a function that get a function like input and return also a function.
for example, in pseudo code
sum(x, y) can get in input two function, two string, two number and return the function x+y
Is this implemented?
Lambda expressions do create functions in the sense that nothing in the lambda expression is evaluated until it is called (lazy evaluation). They encapsulate blocks of code that can be passed around rather than data values that are passed around, and so turn code into data which I guess it the essence of functional programming.
Syntactically I don't think you can call them functions thought because they produce objects with methods, and you need to call the method by name. For example if you have the call:
then the definition of myMethod might look like:
If you could truly call the object that the lambda expression created a function then you would use it something like:
That's more a matter of syntax though, and I would say that the lambda expression behaves very much like a function. It certainly moves Java a lot closer to Haskel than it used to be, but you could ultimately still call myMethod in the code above using an anonymous interface as we would have done in previous versions and it's possible to use Java while making absolutely no use of any of the new functional aspects.