1.Lambda
https://www.cnblogs.com/franson-2016/p/5593080.html
https://www.cnblogs.com/snowInPluto/p/5981400.html
使用时发现lambda 中引用的变量必须用final 或类似final修饰,否则报Variable used in lambda expression should be final or effectively final。可以将变量放进 final数组解决这个问题。
lambda不倾向改变外部变量,最好是在lambda中返回出变量。以下代码最好把list定义写在lambda中
//lambda 要求引用的变量是用final或类似final修饰的,但final修饰了就不能改变值了,ide提示用了AtomicReference 原子引用,
//其实用final List<BaseResourceVM> [] 数组也可以,改变数组本身是final,但改变数组中的值可以
AtomicReference<List<BaseResourceVM>> list = null;
CompletableFuture<AtomicReference<List<BaseResourceVM>>> future = CompletableFuture.supplyAsync(() -> {
if (baseUserVM.getSuperman().equals(true)) {
list.set(EntityUtils.entity2VMList(resourceExtendMapper.selectAllIndxResource(), BaseResourceVM.class));
} else {
list.set(EntityUtils.entity2VMList(resourceExtendMapper.selectIndexResourceByUserId(baseUserVM.getId()), BaseResourceVM.class));
}
return list;
}, FocusBaseThreadPool.getTreadPool());
也知道了一个 AtomicReference 原子引用,可以将对象变为原子,而且是CAS做的,保证修改对象引用时线程安全,这个CAS内部是通过对比对象地址确定是否相同对象。https://blog.csdn.net/fxkcsdn/article/details/82261972
2.Stream
https://www.cnblogs.com/CarpenterLee/p/6545321.html
进阶
https://www.cnblogs.com/CarpenterLee/p/6550212.html