hi all, I've the following nested maps:
Map<String, Map<String, Map<String, Int>>>
and I'm trying to access it by nesting
if
statements. I am trying to increment the value (
Int
) to one provided as argument to a function.
In doing so, I'm encountering an issue:
No set method providing array access
when trying to do something like:
val keyMap = cls.parameter!!["key"] as Map<*, *>
// logic here to increment the value of the last key in the nested map
keyMap[nestedKey1][key] = new_value
the last statement is the one failing with the error shown above
my questions are:
1. how can I access nested maps in a safe manner and when I detect a key not existing, create it and nest in that if statement creating the rest of the map?
2. how can I set the map on an object (
cls.parameter
) such that I preserve other existing mappings and do not override with the new (and what would be the only if written) mapping?