If you are referring to the empBonusAndHikeConsumer field, it's not a BiConsumer of BiConsumer. It's a BiConsumer of an employee and a percentage, just as the other two consumers are.
As the name implies, it accepts two arguments, not three. The bonus parameter in your testBiConsumer() method is used as the argument for both the bonus and the hike parameters of the lambda expressions.
If you study the source code for the BiConsumer.andThen() method, you'll see what Stephan was saying earlier. Bottom line: a composed BiConsumer will use the same arguments for each BiConsumer in the sequence.
What this means to you is that you can't do what you want to do if you want to use these in the spirit they're meant to be used. However, if you really want to do it regardless of how ugly the code gets, you can move the lambda creation into the method and capture the various values from the parameters. This means that you'll essentially ignore the second parameter passed to the lambda. But like I said, it would be ugly and kind of pointless.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
Please always tell us where such material comes from. We can assess the tutorial; most of the tutorials I see on the Net are rather bad.
You are getting confused about the andThen method. Please start by looking at that link. It produces a bi consumer doing two things.
Thanks for the responses. Yes, I see that the requirement for this example cannot be implemented with nested biconsumers. well I did understand the concept of biconsumer, only this example was confusing to me.
Meanwhile this lesson is from tutorial link and this particular lesson is from chapter "Additional Functions" section "Two Argument BiConsumers".
Edit: checked the lesson again, the presenter created empBonusAndHikeConsumer but did not use it anywhere. So in effect I was wrong to call it from testBiConsumer. Strangely though if this field is not used anywhere just defining the nested biconsumer does not seem that useful.
Stephan van Hulst
posted 4 months ago
s ravi chandran wrote:Yes, I see that the requirement for this example cannot be implemented with nested biconsumers.
Be precise when using programming terms. They are not nested. They are chained or composed.
My sample is mostly different from the original example in two ways, one is use of Emp class instead of Employee class which I did not find anywhere and other is use of empBonusConsumer in method testBiConsumer(). So biconsumer empBonusAndHikeConsumer is created and not used anywhere.
Here is the code snippet from lesson:
But the confusion I had with this example is resolved.
posted 4 months ago
s ravi chandran wrote:. . . will correct the title again.. . . .
Please don't; it makes it looks as if we were answering a non‑question.