- Selenium WebDriver Quick Start Guide
- Pinakin Chaubal
- 177字
- 2021-06-24 18:26:24
Lambda expressions and functional interfaces
Lambda expressions are essential in functional programming. Lambda expressions are constructs that exist in a standalone fashion and not as a part of any class. One particular scenario where Lambda expressions can be used is while creating classes which consist of just a single method. Lambda expressions, in this case, help to be an alternative to anonymous classes (classes without names), which might not be feasible in certain situations. We will briefly look at two examples, side by side, of how we can convert a conventional Java snippet into a Lambda expression.
In the following code, we will assign a method to a variable called blockofCodeA. This is just what we are intending to solve with the means of Lambda expressions:
blockofCodeA = public void demo(){ System.out.println("Hello World");
}
The same piece of code can be written using Lambda expressions, as shown here:
blockofCodeA = () -> {
System.out.println("Hello World");
}
Remove the name, return type, and the modifier, and simply add the arrow after the brackets. This becomes your Lambda expression.
- Getting Started with oVirt 3.3
- Modern Web Testing with TestCafe
- Linux系統架構與運維實戰
- 發布!設計與部署穩定的分布式系統(第2版)
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- 循序漸進學Docker
- Extending Bootstrap
- 精解Windows8
- 計算機系統開發與優化實戰
- Instant Optimizing Embedded Systems using Busybox
- Ceph分布式存儲實戰
- 跟老男孩學Linux運維:Shell編程實戰
- Introduction to R for Quantitative Finance
- Windows 7實戰從入門到精通(超值版)
- 從零開始學安裝與重裝系統