gpt4 book ai didi

android - Kotlin - 类型不匹配所需的集合找到列表

转载 作者:行者123 更新时间:2023-12-04 12:59:16 25 4
gpt4 key购买 nike

我需要附加两个 list但它说我:

type mismatch required collection found list

就像下面这样:
val list: List<Cohort> = ArrayList()
private fun fillFromDao() {
val notesObserver: Observer<ArrayList<Cohort?>?>? =
Observer { cohort: ArrayList<Cohort?>? ->
list.toMutableList().addAll(cohort)
}
if (notesObserver != null) {
otherDialogFragmentViewModel.fetchIsFree()?.observe(this, notesObserver)
otherDialogFragmentViewModel.fetchHasCertificate()?.observe(this, notesObserver)
}
}

最佳答案

两个变化:

val list: List<Cohort?> = ArrayList()    ----> add '?' after Cohort
private fun fillFromDao() {
val notesObserver: Observer<ArrayList<Cohort?>?>? =
Observer { cohort: ArrayList<Cohort?>? ->
list.toMutableList().addAll(cohort!!) ----> add '!!' after Cohort
}
if (notesObserver != null) {
otherDialogFragmentViewModel.fetchIsFree()?.observe(this, notesObserver)
otherDialogFragmentViewModel.fetchHasCertificate()?.observe(this, notesObserver)
}
}

关于android - Kotlin - 类型不匹配所需的集合找到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61076807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com