The code below 100% throws java.lang.OutOfMemoryError
Set<Integer> set = new HashSet<>();
new Random().ints(10_000_000,
Integer.MIN_VALUE,
Integer.MAX_VALUE)
.forEach(
v -> {
if(set.contains(v)){
System.out.println(v);
}else{
set.add(v);
}
}
);
AFAIK it's because lambda capture Integer with context? Could anybody explain what exactly happens here?