如何正确更改SparseArray上的HashMap?

问题描述 投票:0回答:1

我更改了:

private val map = HashMap<Int, AuthorizationContentView>()

on

private val map = SparseArray<AuthorizationContentView>()

但是我该如何解决这种情况?

val view = map.getOrPut(position) {
    AuthorizationContentView(context = context)
}
android kotlin hashmap sparse-matrix
1个回答
2
投票

getOrPutMutableMap中的扩展功能。您也可以使用自己的自定义扩展功能对SparseArray执行相同的操作。那就是Kotlin的便捷程度:)

© www.soinside.com 2019 - 2024. All rights reserved.