I was practcing for the OCP test and came across the below code. As per my understanding the answer that i assumed was 11 but the actual answer is 10. Can someone please help me undrerstand this piece of code.
.andThen() has a similar syntax when used on a Consumer and a Function, but very different semantics1
.andThen() and .compose() both involve chaining a result in different ways when it comes to Function/UnaryOperator.
There is still an .andThen() for Consumer, but no result chaining, because there is no Result, only a side effect.
Nice subtle question, I think, that goes to the understanding of these two different functional interfaces.
This understanding gets further muddled, if one is not careful, with the .collect() method. Because that takes parameters of BiConsumer<> type, that very often DO return a result that could be used for chaining, but is not by .collect()but "appears to be" because they work on mutable objects.
I was actually thinking about this state of affairs yesterday and this morning.
Subtleties abound in Lambdas and Streams usage.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss