The type mismatch happens because product.setPurchaseQuantity(pPurchaseQuantity)
returns void
but productList.set(...)
requires an object of type Product
as its second argument.
To update the quantity, you need to get a Product
from the productList
and then operate on the retrieved object. There is no need to set this object again since you are changing an attribute of this object and the reference to it remains in the productList
.
Product product = productList.get(productIndex);
product.setPurchaseQuantity(pPurchaseQuantity);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…