What is the smartest way to copy a Map in Kotlin? -


i'd new instance of map same content map doesn't have built-in copy method. can this:

val newinst = somemap.map { it.topair() }.tomap() 

but looks rather ugly. there more smarter way this?

just use hashmap constructor:

val original = hashmapof(1 "x") val copy = hashmap(original) 

update kotlin 1.1:

since kotlin 1.1, extension functions map.tomap , map.tomutablemap create copies.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -