private fun getRaidType(): List<SelectItem<String>> {
var list = raidType
raidType.forEach{
Log.i("DHG","raidType is $it")
}
list.forEach{
Log.i("DHG","list raidType is $it")
}
viewModel.diskInfo?.value?.forEach {
if (list.contains(it.disktype)) {
list.remove(it.disktype)
Log.i("DHG","list remove is ${it.disktype}")
}
}
list.map {
SelectItem(it, false)
}.apply {
return this
}
}
然后定义raidtype的class
object DiskConstant {
var raidType: MutableList<String> = mutableListOf(
DiskType.RAID0.s,
DiskType.RAID1.s,
DiskType.RAID5.s,
DiskType.RAID10.s
)
当getRaidType()运行过一次list remove了数值 第二次再调用的时候 raidtype的值会改变
java跟c++一样如果不是基本数据类型是值拷贝其他用=赋值都是引用拷贝
正确的写法是 新建一个list 的临时变量
private fun getRaidType(): List<SelectItem<String>> {
var list = mutableListOf(
DiskType.RAID0.s,
DiskType.RAID1.s,
DiskType.RAID5.s,
DiskType.RAID10.s
)
viewModel.diskInfo?.value?.forEach {
if (list.contains(it.disktype)) {
list.remove(it.disktype)
}
}
list.map {
SelectItem(it, false)
}.apply {
return this
}
}