Common Java Streams Mistakes (part 5): Misunderstanding Java Streams Terminal Operations Semantics

preview_player
Показать описание
This video shows various issues associated with using the Java streams reduce() terminal operation, including the need to use the correct identity value and to ensure operations are associative. It also demonstrates what goes wrong when reduce() performs a mutable reduction on a parallel stream.
Рекомендации по теме
Комментарии
Автор

P.P.S. Sorry if this all sounds overly critical - it just looks like this comment section could use a bit more discussions :-)

ArchonLicht
Автор

P.S. Wouldn't it be much nicer to insert line breaks during the reduction itself than in the actual values that are in "allWords" List? 

Also it would probably be better to actually have individual words there than just 3 sentences - having more elements will produce failures more frequently in concurrency scenarios, and the variable name allWords would reflect reality (right now it's a lie - there are no "words" there, there are sentences - which is quite confusing).

ArchonLicht
Автор

Why not use StringBuffer instead of StringBuilder since this is exactly the thread-safe alternative of StringBuilder?

ArchonLicht