Мне нужно создать поверхностную копию map внутри скрипта, чтобы потом изменить один из ключей. Один вариант даёт оператор spread. Но код работает в Jenkins pipeline, а политика нашей организации запрещает этот оператор.
Вызов метода clone() работает, хотя Intellij сообщает "Access to 'clone' exceeds its access rights". Отчасти причина в том, что map создаётся через Jenkins readJSON, который может вернуть похожий на map объект без реализации самого метода clone().
Какой способ поверхностного копирования map наиболее идиоматичен, если исключить spread?
Переведено с английского·Показать оригиналI need to create a shallow duplicate of a map inside my script, allowing me to change one of its keys afterwards. The spread operator provides one approach. But this runs inside a Jenkins pipeline, and our organization's policy disallows that operator.
Calling the clone() method succeeds, though Intellij reports "Access to 'clone' exceeds its access rights". This is partly due to the map having been created through Jenkins readJSON, which might supply a map-like object that doesn't implement the clone() method itself.
Which approach, excluding the spread operator, is most idiomatic for shallow map copying?