Lots of documents have indicated the difference between Map and MutableMap in Kotlin, however, I can't seem to find the difference between HashMap and MutableMap. Can they be used interchangeably? Are there any differences in the implementation level of this 2 data structure? Can someone please elaborate.

正如人们所指出的,MutableMap是一个接口.那么当我使用 map 时,使用mutableMapOf和hashMapOf有什么不同呢?

Thanks.

推荐答案

HashMap是接口MutableMap的实现.从前一个链接:

Hash table based implementation of the MutableMap interface.

There can be other implementations, like LinkedHashMap. You can read the documentation at these links to discover which behaviors are common to all MutableMap implementations, and which are specific to HashMap or LinkedHashMap.

Kotlin相关问答推荐

文本正在被切断在200%的屏幕比例在Jetpack Compose

在Kotlin 有更好的结合方式?

用vararg替换列表的设计弃用警告

哪个更好? Integer.valueOf(readLine()) 或 readLine()!!.toInt()

创建包含 3 个相同项目的列表/使用返回类型重复

Kotlin 日期格式从一种更改为另一种

Kotlin 中多个 init 块的用例?

`this@classname` 在 Kotlin 中是什么意思?

模拟异常 - 没有找到答案

Android Studio 4.0.0 Java 8 库在 D8 和 R8 构建错误中脱糖

Kotlin 单元测试 - 如何模拟 Companion 对象的组件?

runInTransaction 块内的挂起方法

主机名不能为空

Kotlin-通过与属性列表进行比较来筛选对象列表

大小写敏感性 Kotlin / ignoreCase

在 Kotlin 中创建非绑定服务

如何在 Gradle Kotlin DSL 中使用来自 gradle.properties 的插件版本?

有没有办法在Kotlin中设置一个私有常量

在多平台子元素中使用kapt

类型推断失败:RecyclerViewActions.scrollTo()