Java Lambda表达式 [英] Java Lambda expressions

查看:113
本文介绍了Java Lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java 8中添加了Lambda表达式。我想理解为什么这很重要。对于尚未接触函数式编程习惯用语的Java程序员来说,这意味着什么?这是否意味着我可以编写性能更好或大规模扩展的代码,或者只是使代码更简洁。或者全部。

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.

推荐答案

Oracle已经有教程。它列出了几个很好的用例。

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

在找到链接之前,我想说lambda表达式允许你将函数传递给代码。因此,您可以更轻松地编写代码,以前我们需要一大堆接口/抽象类。例如,假设您的代码具有一些复杂的循环/条件逻辑或工作流。一步你想要做一些不同的事情。使用lambda表达式,您可以传入不同的东西。但是请阅读教程。这很清楚。

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.

这篇关于Java Lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆