object - Kotlin 等价于 python self.__dict__.get(item)
问题描述
我正在编写一个存储类来存储具有唯一 ID 的变量。在python中,我使用了这个。我会在 Kotlin 中使用什么?
在查看文档时,我已经尝试过使用看似等价的东西,但没有一个奏效。
解决方案
HashMap是您正在寻找的。例子:
val hashMap = HashMap<Int, String>()
hashMap.put(12, "str")
hashMap.put(-1, "something else")
推荐阅读
- android - Android:计算 SparseArray VS HashMap 的内存占用
- ios - 在您单击以在 iPad 上显示侧边栏之前,三列导航视图不会更新
- c# - ASP.NET API 版本范围
- generics - 如何将通用对象传递到 Blazor 中的另一个页面?
- datetime - 如何在 Apps Script for Sheets 中为单元格的输入指定时区
- r - R中如何选择Rpart包中的根节点
- mysql - 从 .csv 加载 MySQL 数据,但缺少一些数据!第 1 行被截断;它包含的数据多于输入列
- java - 无法使用 ActionListener
- javascript - 在 JavaScript 中的秒数后退出获取尝试
- amazon-web-services - Fargate 配置文件中的错误:FargateECSTaskDefinition