So I’m reading a book on Java, and it’s talking about lambdas. The syntax seems simple enough, but the author hasn’t described why you would use them over a regular function. They’re being used in the context of functions that don’t have bodies (abstracts, I think?), but I don’t understand why I would use those either.
[Java] ELI5 Lambda expressions
Java 8 idioms: Why the perfect lambda expression is just one line
Introduction to Lambda Expressions in Java
High level overview of Lambda Expressions in Java 8
Personally, I find it easier to think of lambdas as just syntactic sugar for interfaces with a single abstract method. It's not clear from the post when they can be used (e.g. not for abstract classes). Also, converting a for-loop to use forEach doesn't require a lambda. It's much cleaner with lambdas, but I could see someone getting confused as to when lambdas can/should be used.
More on reddit.comVideos
Hey,
I'm learning java right now and I have problems understanding them. I already googled, I read you can use them to return methods. I don't really get it, in which case would you have to return a method and how would you use a returned method?
If someone could explain Lambda expressions to me that would be great!