我需要附加两个 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/