It is not a duplicate, all duplicate links are suggesting for final but I clearly said I knew about it, what I need is an explanation for the Atomic part. So the question is why Atomic?
Any explanation on why IntelliJ is suggesting to convert it into Atomic.
There was another suggestion to declare final, which I understand the lambda needs to capture the value and doesn't want it to change outside its scope.
boolean myvar = true;
env.forEach((key, value) -> {
System.out.println(key + " " + value);
if(value == null) myvar = false;
});
after changing to atomic, it looks like this.
AtomicBoolean myvar = new AtomicBoolean(false);
env.forEach((key, value) -> {
System.out.println(key + " " + value);
if(value == null) myvar.set(false);
});
after converting to final, it suggests again to convert into one element array.