Java8有好多新的写法,眼花缭乱,如下:
Stream写法
例子1:
Java以前的写法
List<Long> recordsIDlist = new ArrayList<>(retrecordsList.size());
retrecordsList.forEach(item -> {recordsIDlist.add(item.getRecordId());});
Java8 新写法
List<Long> recordsIDlist=
retrecordsList.stream().map(DiffStatementsSnapshot::getRecordId).collect(Collectors.toList());
或者为:
List<Long> recordsIDlist= retrecordsList.stream().map(item -> item.getRecordId()).collect(Collectors.toList());
ofNullable用法
return Optional.ofNullable(OFFSET_CACHE.get(coupleInfo.getCoupleId())).map(WeakReference::get).orElseGet(() -> {
OffsetCondition offsetCondition = JSON.parseObject(coupleInfo.getOffsetCondition(), OffsetCondition.class);
OFFSET_CACHE.put(coupleInfo.getCoupleId(), new WeakReference<>(offsetCondition));
return offsetCondition;
});
参考文档:
1. https://blog.youkuaiyun.com/qq_38360675/article/details/103089167
2.https://blog.youkuaiyun.com/zjhred/article/details/84976734