is there a way to choose what concrete type `assoc...
# getting-started
k
is there a way to choose what concrete type
associateWith
returns?
🚫 1
h
No.
LinkedHashMap
is hardcoded in the stdlib. You could only use
associateWithTo
to add the results to an existing (mutable) map of your choice.
👍 2
k
thanks!
e
Kotlin specifies that
mapOf
,
mutableMapOf
, and most Map-returning methods preserve insertion order, so in practice they are backed by LinkedHashMap
👍 1
but yes,
associateWithTo
(like other
*To
methods) returns the collection itself, so you can write
Copy code
val myMap = foo.associateWithTo(MyMapType()) { ... }
with the result of
myMap: MyMapType
👍 1