Lambdas in Java 8 can only access variables from the surrounding block as read-only. For example, if you want to calculate the sum of numbers between 1 and 100, this gives you a compile-time error:
int x = 0; IntStream.rangeClosed(1, 100).forEach(i → x += i);
If memory serves me well, in Pascal, local functions could also write to the variables they could see.
Lambdas in Java 8 can only access variables from the surrounding block as read-only. For example, if you want to calculate the sum of numbers between 1 and 100, this gives you a compile-time error:
If memory serves me well, in Pascal, local functions could also write to the variables they could see.