I want to sum a list of double variable that are values of a Hashmap. But I want to do it with lambda expression not with entrySet or sth else.
HashMap <Integer,Double> h=new HashMap<Integer,Double>();//I've put some key,value pairs in it
double sum =0.0;
h.forEach((k,v)->{
sum+=v;
});
System.out.println(sum);
But it says; Local variable sum defined in an enclosing scope must be final or effectively final. How could I solve this?