- 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.
- Kubernetes修煉手冊
- Linux從零開始學(xué)(視頻教學(xué)版)
- 白話區(qū)塊鏈
- 嵌入式Linux驅(qū)動程序和系統(tǒng)開發(fā)實(shí)例精講
- 高性能Linux服務(wù)器構(gòu)建實(shí)戰(zhàn):系統(tǒng)安全、故障排查、自動化運(yùn)維與集群架構(gòu)
- Mobile First Design with HTML5 and CSS3
- STM32庫開發(fā)實(shí)戰(zhàn)指南:基于STM32F4
- Android物聯(lián)網(wǎng)開發(fā)細(xì)致入門與最佳實(shí)踐
- AWS Development Essentials
- Linux內(nèi)核設(shè)計的藝術(shù):圖解Linux操作系統(tǒng)架構(gòu)設(shè)計與實(shí)現(xiàn)原理
- 計算機(jī)系統(tǒng):基于x86+Linux平臺
- Windows 7應(yīng)用入門與技巧
- 分布式系統(tǒng)設(shè)計實(shí)踐
- 精解Windows 10
- Building Telephony Systems With Asterisk