一、lambda出现的背景
- 精简代码
Runnable runnable1 = new Runnable() {
@Override
public void run() {
System.out.println("runned111");
}
};
Runnable runnable = ()->{
System.out.println("runned0");
};
- 实现回调函数的特点
我们知道在JavaScript中,一个函数是可以作为参数传入另一个函数的,这就为一种“即用即走,低耦合”的思想提供了很好的实现
TestStd<String> std = new TestStd(Arrays.asList("1","1","1","1","124","124","124","124"));
// 可以看做回调函数
Function<String,Integer> function = (v1)->Integer.parseInt(v1);
List<Integer> integers2 = std.map2(function);