小编use*_*638的帖子

Kotlin:类型推断失败。预期类型不匹配:推断类型为 MutableList<Long?> 但预期为 MutableCollection<Long>

我正在尝试使用 kotlin 创建一个 MutableList 但我收到一条错误消息:

类型推断失败。预期类型不匹配:推断类型为 MutableList 但预期为 MutableCollection

...而且我不确定如何将 MutableList 转换为 MutableCollection。

我试过使用:

.toMutableList().toCollection()
Run Code Online (Sandbox Code Playgroud)

但它正在寻找目的地——我不知道该怎么做。

代码片段:

data class HrmSearchResult(
    var rssi: Short?,
    var adjustRssi: Short?,
    var timeout: Int,
    var serialNumber: Long?,
    var isIn: Boolean,
    var countIn: Int
)

private val hashMapHrm = ConcurrentHashMap<Long?, HrmSearchResult>()

val hrmDeviceList: MutableCollection<Long>
    get() = try {
        if (hashMapHrm.elements().toList().none { it.isIn}) {
            //if there are no member in range, then return empty list
            arrayListOf()
        } else {
            hashMapHrm.elements()
                .toList()
                .filter { it.isIn }
                .sortedByDescending { …
Run Code Online (Sandbox Code Playgroud)

collections android mutable kotlin

5
推荐指数
1
解决办法
6649
查看次数

标签 统计

android ×1

collections ×1

kotlin ×1

mutable ×1