I'm attempting to create a MutableList using kotlin but I'm getting an error stating:
Type inference failed. Expected type mismatch: inferred type is MutableList but MutableCollection was expected
...and I'm not sure how to convert the MutableList to a MutableCollection.
I've tried using:
.toMutableList().toCollection()
but it's looking for a destination - and I'm not sure what to do.
Code Snippet:
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 { it.adjustRssi }
.map { it.serialNumber }
.toMutableList().toCollection()
}
} catch (ex: Exception) {
AppLog.e(
LOG, "Problem when get devices " +
"return empty list: ${ex.localizedMessage}"
)
arrayListOf()
}
Any suggestions are appreciated.