Well I'm digging through Java8 lambda and I'm facing following problem - lambda doesn't change data:
DamnLambda.class:
public static void inc ( List<Integer> list, Funtion<Integer,Integer> func) {
for(Integer intr : list) {
intr = func.apply(intr);
}
Let's try to invoke:
List<Integer> l = Arrays.asList(1,2,3);
DamnLambda.inc(l, x -> x+=1);
System.out.println(l); //[1,2,3] ? Why not [2,3,4] ?
I can't understad why it doesn't change any data. I tried also different version of same functionality:
l.forEach(x -> x+1); //same thing, doesn't change the data.
What am I missing here?