Am trying to iterate an ArrayList using Java 8 - Lambda forEach and to store the value in the global variable.
Am getting the error like type mis-match and am not able to typecast also.
Please see my code below.
Long product_id = listProducts.forEach(listproducts ->listproducts.getId());
My Previous approach : (without JAVA8 feature, now i want to change my code by using Java8)
for(Product prod : listProducts)
{
product_id=prod.getId();
}
forEachdoesn't return anything. What exactly do you expect the output to be. You are processing a list of elements and seem to require a single value as the output.product_idwill be overwritten.