talk about java lamda and oop

japhy :

we know that Java is an OOP language, since Java 8, we can use Lambda. But I have some questions and hope anyone can give me some advice.

  1. What is the difference between action and method?
  2. Lambda defines an action, it seems against the OOP. We used to write methods in an object to define its action. And then we get an instance of that object by the keyword new. That instance has its fields and methods, so it becomes a subject, a role. But Lambda just destroys this structure. I wonder how to use Lambda properly in the project.
GhostCat salutes Monica C. :

Java is an OOP language, but throughout the last years, Java, like many other important languages tries to become more FP (think C++ for example, and all the FP support that got added to it lately).

One core element of Functional Programming: higher order functions. "Code that does something" becomes something you can define on its own, and pass around.

So, yes, in a strict OOP sense lambdas, and closures look awkward. But Java is simply following a specific trend here.

And, personal opinion now: Java does that to stay relevant. The OOP concept was "invented" to solve a very specific set of problems, and many other problems can be expressed/solved using FP paradigms in much better/elegant ways.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=103508&siteId=1