Lambda表达式简化过程
package com.lee.lambda;
//推导lambda表达式
public class TestLambda1 {
//3.静态内部类
static class Like1 implements ILike{
@Override
public void sad() {
System.out.println("Lambda1表达式学习!");
}
}
public static void main(String[] args) {
ILike like = new Like();
like.sad();
ILike like1 = new Like1();
like1.sad();
//4.局部内部类
class Like2 implements ILike{
@Override
public void sad() {
System.out.println("Lambda2表达式学习!");
}
}
ILike like2 = new Like2();
like2.sad();
//5.匿名内部类,没有类的名称,必须借助接口或者父类。
ILike like3 = new ILike() {
@Override
public void sad() {
System.out.println("Lambda3表达式学习!");
}
};
like3.sad();
//6.lambda表达式
ILike like4 = ()-> {
System.out.println("Lambda4表达式学习!");
};
like4.sad();
}
}
//1.定义一个函数式接口
interface ILike{
void sad();
}
//2.实现类
class Like implements ILike{
@Override
public void sad() {
System.out.println("Lambda表达式学习!");
}
}