我正在尝试放入类型为list<项目>进入另一个列表类型列表在kotlin。
suspend fun insertNotifLocal(list: List<NotificationItems?>) = viewModelScope.async(IO){
repository?.insertNotifLocal(list)
}
我不完全理解您在查看代码片段时要做什么,但根据标题,我可以提供一些输入:
如果您有一个List<Any?>
,并希望将其作为参数List<Any>
的参数传递,则必须确保列表不再包含null,例如使用filterNotNull
:
fun process(any: List<Any>): Int = any.size
fun main() {
val nullableList: List<Any?> = listOf(null, 2, "two")
process(nullableList.filterNotNull())
}