当前位置:网站首页>lambda expressions
lambda expressions
2022-04-23 06:01:00 【hanyc..】
In this case , From ordinary class -> Static inner class -> Local inner classes -> Anonymous inner class ->lambda expression , The overall complexity of the code is from complex to simple .
Functional interface : Any interface , If there is only one abstract method , So it's a functional interface .
For functional interfaces , We can go through lambda Expression to create the object of the interface
- lambda An expression can only be reduced to one line if it has only one line of code , If there are many lines , Then wrap it in code blocks
- The premise is that the interface is functional
- Multiple parameters can also be removed from the parameter type , If you want to get rid of everything , It has to be bracketed ( Parentheses can be omitted for a single parameter )
package creatthread;
public class TestLambda {
//2、 Static inner class
static class DrinkSpirit implements Drink {
@Override
public void haveADrink(String name, String drinkType) {
System.out.println(name + " Drinking " + drinkType);
}
}
public static void main(String[] args) {
//3、 Local inner classes
class DrinkFanta implements Drink {
@Override
public void haveADrink(String name, String drinkType) {
System.out.println(name + " Drinking " + drinkType);
}
}
System.out.println("============ Common classes implement interfaces ===============");
Drink drink1 = new DrinkCola();
drink1.haveADrink(" Zhang Yi ", " coke ");
System.out.println();
System.out.println("============ Static inner class ==============");
Drink drink2 = new DrinkSpirit();
drink2.haveADrink(" Li Er ", " Sprite ");
System.out.println();
System.out.println("============ Local inner classes ==============");
Drink drink3 = new DrinkFanta();
drink3.haveADrink(" The king of the three ", " Fanta ");
System.out.println();
System.out.println("============ Anonymous inner class ==============");
Drink drink4 = new Drink() {
//4、 Anonymous inner class
@Override
public void haveADrink(String name, String drinkType) {
System.out.println(name + " Drinking " + drinkType);
}
};
drink4.haveADrink(" Zhao si ", " coffee ");
System.out.println();
System.out.println("============lambda expression ==============");
//5、lambda expression
//lambda The expression returns an interface
Drink drink5 = (name, drinkType) -> System.out.println(name + " Drinking " + drinkType);
drink5.haveADrink(" Qian Wu ", " milk ");
}
}
interface Drink {
public void haveADrink(String name, String drinkType);
}
//1、 The interface is implemented through ordinary classes
class DrinkCola implements Drink {
@Override
public void haveADrink(String name, String drinkType) {
System.out.println(name + " Drinking " + drinkType);
}
}
result :

版权声明
本文为[hanyc..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230541159237.html
边栏推荐
- 基于thymeleaf实现数据库图片展示到浏览器表格
- PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
- Solution record of slow access speed of SMB service in redhat6
- Remedy after postfix becomes a spam transit station
- Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
- Software architecture design - software architecture style
- Graphic numpy array matrix
- Pytorch——数据加载和处理
- Opensips (1) -- detailed process of installing opensips
- Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
猜你喜欢
![对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning](/img/21/4bc94fe29f416c936436c04fc16fa8.png)
对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning

Create binary tree

自動控制(韓敏版)

数字图像处理基础(冈萨雷斯)二:灰度变换与空间滤波
![Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots](/img/fd/84df62c88fe90a73294886642036a0.png)
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots

Implementation of displaying database pictures to browser tables based on thymeleaf

Development environment EAS login license modification

Configure domestic image accelerator for yarn

Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code

Pytorch学习记录(五):反向传播+基于梯度的优化器(SGD,Adagrad,RMSporp,Adam)
随机推荐
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Numpy common function table sorting of data processing
域内用户访问域外samba服务器用户名密码错误
Anaconda
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
线代第四章-向量组的线性相关
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)
你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
EditorConfig
Pytorch学习记录(九):Pytorch中卷积神经网络
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
The official website of UMI yarn create @ umijs / UMI app reports an error: the syntax of file name, directory name or volume label is incorrect
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
金蝶EAS“总账”系统召唤“反过账”按钮
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
JSP syntax and JSTL tag