当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢

积分专题笔记-与路径无关条件

Windows 下安装 MySQL

负电压电路(原理分析)

Splunk tag 的利用场景

Detailed explanation of 4D words: C language three-point chess advanced + N-piece chess recursive dynamic judgment of winning or losing

How to implement Golang DES encryption and decryption?

电源完整性的去耦和层间耦合电容

How to avoid CMDB becoming a data island?

信号完整性测试

conda 导出/导出配置好的虚拟环境
随机推荐
FPGA基础协议二:I2C读写E²PROM
【Flask框架②】——第一个Flask项目
test4
HashSet and LinkedHashSet
conda 导出/导出配置好的虚拟环境
积分简明笔记-第二类曲线积分的类型
leetcode力扣——一篇文章解决多数之和问题
最远点采样 — D-FPS与F-FPS
How to run dist file on local computer
jdbc ResultSetMetaData获取tableName问题
Apache DolphinScheduler's new generation of distributed workflow task scheduling platform in practice - Part 1
公共Jar包的版本管理
Detailed description of iperf3 parameter options
XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
深入浅出零钱兑换问题——背包问题的套壳
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上
HashSet和LinkedHashSet
无法定位程序输入点ucrtbase.abort于动态链接库api-ms-win-crt-runtime-|1-1-0.dll上
MySQL Explain 使用及参数详解
如何组装一个注册中心