当前位置:网站首页>Functional Interfaces & Lambda Expressions - Simple Application Notes
Functional Interfaces & Lambda Expressions - Simple Application Notes
2022-07-30 09:33:00 【Rose*leave blank ق೨】
The following is an understanding based on data and experiments:
1、LambdaThe use of expressions is related to functional interfaces
2、函数式接口有且仅有一个抽象方法
函数式接口、LambdaIf you don't understand the expression, you can refer to other articles
The following code can be copied and pasted by yourself to see the execution effect
//函数式接口 There is only one method in the interface
@FunctionalInterface
public interface MyFunctionalInterface {
int test(int a,int b);
}
import java.util.ArrayList;
import java.util.List;
public class testLambda {
private static int sum(MyFunctionalInterface myFunctionalInterface,int a,int b){
return myFunctionalInterface.test(a,b);
}
public static void main(String[] args) {
//LambdaClassic example of expression
List<String> list = new ArrayList<>();
list.add("abc");
list.add("def");
list.add("ghi");
list.forEach(item -> System.out.println(item));
//Basic use of functional interfaces 基本语法: (parameters) -> expression 或 (parameters) ->{ statements; }
MyFunctionalInterface myFunctionalInterface = (int a,int b)-> {
return a+b;
};
//简写
MyFunctionalInterface myFunctionalInterface1 = (int a,int b)-> a+b;
int result = myFunctionalInterface1.test(3,2);
System.out.println(result);
//A typical use case for a functional interface is as a parameter to a method
int result1 = sum((int a,int b) -> a+b,20,36);
System.out.println(result1);
}
}
边栏推荐
猜你喜欢

读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》

Concise Notes on Integrals - Types of Curve Integrals of the Second Kind

MySQL中使用IN 不会走索引分析以及解决办法

SEER数据库中“手术变量(RX SUMM-SURG OTH REG/DIS )”下的字段解释

XP电源维修fleXPower电源X7-2J2J2P-120018系列详解

延迟队列MQ

【Flask框架②】——第一个Flask项目

20220728使用电脑上的蓝牙和汇承科技的蓝牙模块HC-05配对蓝牙串口传输

How to avoid CMDB becoming a data island?

剖析SGI STL空间配置器(allocate内存分配函数)
随机推荐
利用R语言读取csv文件入一个数据框,然后查看各列的属性。
公共Jar包的版本管理
Splunk tag 的利用场景
【愚公系列】2022年07月 Go教学课程 021-Go容器之切片操作
仿牛客网项目第二章:开发社区登录模块(详细步骤和思路)
hcip 第14天学习笔记
经历了这样一个阶段的发展之后,数字零售才能有新的进化
最远点采样 — D-FPS与F-FPS
开关电源波纹的产生、测量及抑制,一篇全搞定!
Explain the problem of change exchange in simple terms - the shell of the backpack problem
2022 Hangzhou Electric Multi-School 1st Game
XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
剖析SGI STL空间配置器(allocate内存分配函数)
经典毕业设计:基于SSM实现高校后勤报修系统
Farthest Point Sampling - D-FPS vs F-FPS
Concise Notes on Integrals - Types of Curve Integrals of the First Kind
[Yugong Series] July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
Excel xlsx file not supported两种解决办法【杭州多测师】【杭州多测师_王sir】
HCIP --- MPLS VPN实验
Network/Information Security Top Journal and Related Journals Conference