List.of(a,b,c).forEach(it->it=null);// mutate the data
This code doesn't change the data at all. The list continues to be the same after the forEach. This code above is the same as this:
vara="a";varb="b";varc="c";varlist=List.of(a,b,c);list.forEach(it->it=null);// mutate the dataSystem.out.println(list);// prints [a, b, c]for(varx:list){x=null;}System.out.println(list);// prints [a, b, c]
Passionate developer in Java and Scala. And sometimes, something else. A few months per year, someone calls me "professor". CoFounder of Scala By The Lagoon @scalagoon
This code doesn't change the data at all. The list continues to be the same after the forEach. This code above is the same as this:
The data continues to be immutable.
If you need
val
immutability, Scala is just a few jars away, And VSCode support with Metals is getting really good.