When I call `.withDefault` on a map, the default b...
# announcements
s
When I call
.withDefault
on a map, the default behavior seems to be lost if I call another method (e.g.
toMutableMap
) on that map instance. Is that expected/documented behavior? I couldn't find clear rules in the docs.
k
I think the problem is that
withDefault
breaks the
Map
contract in that it "contains" things that are not listed in
map.entries
.
toMutableMap
has to create a new map by iterating the entries, so I think this behaviour is kind of expected.
👍 2
a
@stkent I tend to use the
map.getOrPut()
to insert missing entries into the map on the retrieval.
1
s
Mmm, that could be safer, thanks!