June 2018
Beginner
722 pages
18h 47m
English
As in the anonymous class, the variable, created outside and used inside the lambda expression, becomes effectively final and cannot be modified. You can write the following:
int x = 7;//x = 3; //compilation errorint y = 5;double z = 5.;supplyDecideProcessAndConsume(() -> x, d -> d < y, i -> i * z, d -> { //x = 3; //compilation error System.out.println("Result=" + d + " Great!"); } );
But, as you can see, we cannot change the value of the local variable used in the lambda expression. The reason for this restriction is that a function can be passed around and executed in different contexts (different threads, for example), and the attempt to synchronize these contexts would defeat the original idea of the stateless ...
Read now
Unlock full access