Sorry for this late response. It's been a pretty busy weekend.
Let me try to clarify some of what I said previously with examples.
OP wrote:...trying out different ways to fail
That's a perfectly fine way to learn. Yoda even said that "The greatest teacher, failure is."
Piet may have already gone over this but I'll reiterate: Your attempt to use a Consumer lambda failed because of the expression c.getCount() += 1
. The += operator is a compound operation which combines an addition operation with an assignment operation. It's illegal to try to assign a value to a method call, which is what c.getCount()
is, hence the error message that says "the left hand side of an assignment must be a variable".
OP wrote:why do you say "between the StateCount class and the lambdas"
I think it's because I didn't see any reason for the lambda to know about StateCount. I got a sense that the code you wrote was going around the bush to do something that could be accomplished in a more straightforward manner. If I really wanted to use lambdas to do increment/decrement, I would have done something like this:
You can try this code out yourself here: https://repl.it/@jlacar/SupplierLambdasExample
Study that example for a while and come back if you have any questions.