I have this code that works fine:
String name = "Oscar";
CompletableFuture.runAsync(() -> doX(name));
Now I need to add some logic to the name
variable:
String name = "Oscar";
if (x){
name = "Tiger";
}
CompletableFuture.runAsync(() -> doX(name));
But now the compiler complains about Variable used in lambda expression should be final or effectively final
I understand from posts like this one that the name
must be final
or effectively final, but I wonder if there is a way to write the code differently in order to enable the logic on the name
variable