Lambda
new Thread(()->System.out.println("多线程学习....")).start;
/*
* 避免匿名内部类定义过多
* 可以让你的代码看起来整洁
* 去掉了一些没有意义代码,只留下核心代码
*
* */
//lambda简化代码过程
public class TestLambda {
//1.静态内部类
static class Like2 implements ILike{
@Override
public void lambda() {
System.out.println("lambda2");
}
}
public static void main(String[] args) {
ILike like=new Like();
like.lambda();
//调用静态内部类
like=new Like2();
like.lambda();
//2.局部内部类
class Like3 implements ILike{
@Override
public void lambda() {
System.out.println("lambda3");
}
}
like=new Like3();
like.lambda();
//3.匿名内部类
like=new ILike() {
@Override
public void lambda() {
System.out.println("lambda4");
}
};
like.lambda();
//4.lambda表达式
like=()-> System.out.println("lambda5");
like.lambda();
}
}
interface ILike{
void lambda();
}
class Like implements ILike{
@Override
public void lambda() {
System.out.println("lambda");
}
}
Lambda带参数
public class TestLambda1 {标签:like,void,System,Lambda,out,public,表达式,lambda From: https://www.cnblogs.com/wukangxiang/p/17284498.html
public static void main(String[] args) {
ILove love=(a)->System.out.println("我爱"+a);
love.love(1236544354);
}
}
//lambda表达式只能有一行代码的情况下才能简化成为一行,如果有多行,那么就用代码块包裹
//前提接口是函数式接口
interface ILove{
void love(int a);
}