I've got a function like the following where I need to update a variable from inside lambda (This is the minimal viable example I could think of without giving our private info so it might not make much sense, but the lambda and stage variables are there).
But as expected, I can't update the variable since I get the error Variable used in lambda expression should be final or effectively final
. What is the best way to update an external variable from within the lambda. The purpose of the variable is to know which stage the process failed in case something goes wrong, which means it can fail without returning anything.
(() -> {
stage = "Validating";
//do something
stage = "Creating x";
// do something
stage = "Creating y";
// .....
stage = "finalising";
// do something
})