首页 > 解决方案 > Kotlin 等价于 python self.__dict__.get(item)

问题描述

我正在编写一个存储类来存储具有唯一 ID 的变量。在python中,我使用了这个。我会在 Kotlin 中使用什么?

在查看文档时,我已经尝试过使用看似等价的东西,但没有一个奏效。

标签: objectvariableskotlinglobal

解决方案


HashMap是您正在寻找的。例子:

val hashMap = HashMap<Int, String>()
hashMap.put(12, "str")
hashMap.put(-1, "something else")

推荐阅读