kotlin - 我如何插入列表- 到列表
- 在科特林
问题描述
我正在尝试将 List<Item?> 类型的列表放入 kotlin 中的另一个 List 类型列表中。
suspend fun insertNotifLocal(list: List<NotificationItems?>) = viewModelScope.async(IO){
repository?.insertNotifLocal(list)
}
解决方案
我不完全理解您在查看代码片段时要做什么,但根据标题,我可以提供一些输入:
如果您有 aList<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())
}
推荐阅读
- reactjs - React hooks 如何根据 props 变化更好地更新多个状态
- php - 如何在 foreach 循环 PHP 中使用 2 个数组来选择随机元素
- github - Airflow 代码库正在使用过时的提交。我如何指出它是最新的?
- datatable - 如何设置要在没有分页的角度7数据表中显示的行
- java - Spring Boot Async 将一些数据传递给服务器,等待响应作为文件
- java - 在实施 vigenere 密码时需要帮助
- swift - 为什么以协议为参数的函数不适用于符合 Swift 中相同协议的类型扩展?
- mysql - 如何修复错误 1452 并正确关联表
- function - Powershell 只需要函数中的值
- javascript - React,如何将值从函数返回到组件?