https://kotlinlang.org logo
#android
Title
# android
a

Ayden

07/30/2018, 7:14 AM
Copy code
val parameterObject = element?.asJsonObject
val parameters: Map<String, List<String>> = HashMap()
for (entry in parameterObject?.entrySet().orEmpty()) {
    val key = entry.key
    val value = entry.value.asString
    parameters.put(key, value)
}
l

Lucas Ł

07/30/2018, 7:16 AM
a

Ayden

07/30/2018, 7:17 AM
Thanks @Lucas Ł!
a

arekolek

07/30/2018, 7:21 AM
your map is mutable, but then you narrow the type down to immutable
either do
Copy code
val parameters = HashMap<String, List<String>>()
or
Copy code
val parameters: MutableMap<String, List<String>> = HashMap()
l

Lucas Ł

07/30/2018, 7:22 AM
or
Copy code
val parameters = mutableMapOf<String, List<String>>()
a

arekolek

07/30/2018, 7:24 AM
I assumed he cared about the implementing type, but if you don't care about it, that's the best one to use
a

Ayden

07/30/2018, 7:32 AM
Thanks guys.
I managed to implement it.
I though if I don't defined anything.
I would be MutableList by default.
a

arekolek

07/30/2018, 7:41 AM
only if it comes from Java
t

thymecypher

07/30/2018, 11:38 PM
Let's not get into the ways we could do this. This is Kotlin, we'd be here all year :p