Chaining Consumers Java 8

本小妞迷上赌 提交于 2019-12-01 07:15:44

You are probably trying to solve a problem that does not exist. I think it is perfectly normal to do any change to an object with map() no matter how small the change is.

My understanding is that there is no semantic meaning behind operations like map() or peek(), and you can use either of them for any task where it suits.

peek() is often used for debugging: it allows you to log every item in the stream without using a terminal operation and destroying the stream. map() is used when you need to do something with objects and pass them forward.

Also, think about it: the method in the Consumer interface has one input parameter and it does not return any value. If your input parameter is immutable, it makes it impossible to return any value from this method without any dirty tricks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!