The naive code I have is:
class ${
public static void main(String[] _) {
final List<Integer> ints = new ArrayList<>();
IntStream.iterate(0, i -> i++).limit(5).forEach(val -> ints.add(val));
System.out.println(ints);
}
}
where my expectation was to see the following in the console:
[0, 1, 2, 3, 4]
But the actual is:
[0, 0, 0, 0, 0]
It is probably something very simple, but what am I missing?