无法更改MutableList中的对象属性 [英] Unable to change an object property in MutableList

查看:85
本文介绍了无法更改MutableList中的对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果列表中还存在具有相同ID的对象,我正在尝试更改对象的MutableList中的数量,问题是尝试执行it.qty += qty

以下是android studio在说什么的屏幕:

如果有用的话,这里是我的Articolo类代码:

data class Articolo(var barcode: String, var qta: Number) {
    constructor() : this ("", 0)
}

以及屏幕截图中的代码:

private var articoli = mutableListOf<Articolo>()
    articoli.find{
        it.barcode==barcode
    }?.let{
        it.qta += qta
    }?:{
        articoli.add(Articolo(barcode, qta))
    }

解决方案

无法将qta定义为Number,Number是一个接口,没有加号方法

将其定义为Int Long Double或其他特殊类型

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))
    }

解决方案

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

这篇关于无法更改MutableList中的对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆