I have a for each loop
iterating in a list. I add a object to another Object list then i modify the value of the object then I add to another list.
Problem is first list value also changed after modifying the object before adding to the second list.
I am facing this type of reference/memory issue all over the project. In previous, i faced memory/reference issue even if i use new Keyword / addAll() etc method to copy list data.
orderListNormal = new HashMap<>();
orderListDelete = new HashMap<>();
orderListExtra = new HashMap<>();
for (Integer hashcode :
salesOrderList.keySet()) {
OrderSalesModel order = salesOrderList.get(hashcode);
if (order.getQuantityAvailable() == 0) {
if (isDirectOrder) {
processOrderListener.invalidQuantity();
return;
}
double regular = order.getQuantity();
double extra = order.getQuantity() - order.getQuantityAvailable();
regular = regular - extra;
order.setQuantity(regular);
orderListNormal.remove(hashcode);
orderListDelete.put(hashcode, order);
order.setOrderDetailID("0");
order.setQuantity(extra);
orderListExtra.put(hashcode, order);
}
......
}