Unable to change an object property in MutableList

廉价感情. 提交于 2021-01-29 08:27:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!