问题
I'm trying to change quantity in my MutableList of an Object if there is yet that object with same ID in the list, the issue is that i'm getting bunch of errors when trying to do it.qty += qty
Here is a screen of what android studio is saying:
If it would be useful here is my Articolo class code:
data class Articolo(var barcode: String, var qta: Number) {
constructor() : this ("", 0)
}
And the code from the screenshot:
private var articoli = mutableListOf<Articolo>()
articoli.find{
it.barcode==barcode
}?.let{
it.qta += qta
}?:{
articoli.add(Articolo(barcode, qta))
}
回答1:
can't defined qta as Number,Number is an interface ,it has no plus method
defined it as Int Long Double or other special type
来源:https://stackoverflow.com/questions/65772605/unable-to-change-an-object-property-in-mutablelist