目录
背景
这周遇到了一件很有意思的事情。在看项目代码时,发现了这么一段:
return objects.stream()
.peek(object -> addInfo(object, someParams))
.collect(Collectors.toList());
因为之前没接触过 peek()
,这段代码看得我云里雾里。
后来在 这个链接 里读到这样一句话:
On top of that, peek() can be useful in another scenario: when we want to alter the inner state of an element.
翻译过来就是:
除此之外,peek() 还有另一种用途:改变元