Here is a sample of a code that uses an array int[]
instead of an int
. All lines containing i
are shown in the the code below. This method is executed by several threads.
int[] i = {0}; //So the stream forEach doesn't complain about a potentially final variable to use...
result.forEach (currentOptionRow -> {
String bgColor = (0 == i[0] % 2) ? "eaeaea" : "ffffff";
//Create HTML, use bgColor to generate alternating background
i[0]++;
});
Is this a workaround to get a mutable counter?
Why is it "potentially final"? (There is no final
keyword, why is it a concern?)