I want to set value to a field of an object so that it will first get the previous value of that field and append something to it and the set it to that field.
In LambdaJ forEach we can do something like this:
forEach(myCollection).setFieldValue("someValue");
But what I need is:
forEach(myCollection).setFieldValue(getFieldValue() + "someValue");
Is it possible in LambdaJ?
I had a similar usecase and realized forEach won't help the way I used it.
So I thought closures are a solution:
But the asserts fails since the object in the collection is not been modified. Maybe I'm doing something wrong there.
In the end I used closures from the apache commons collection.
UPDATE
I was able to solve the puzzle with a closure. Looks like you can't use the free variable direct. Here is the working code:
Note: instead of
thisyou can also write a class which contains thevisitmethod and use it in the definition of theclosure.