我需要附加两个list,但它告诉我:
type mismatch required collection found list
Run Code Online (Sandbox Code Playgroud)
就像下面这样:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 3
两个变化:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13019 次 |
| 最近记录: |