Posts

Showing posts with the label anko

How can I convet MutableMap to vararg values: Pair?

How can I convet MutableMap<String, Any?> to vararg values: Pair<String, Any?>? The following code is from "Kotlin for Android Developers", you can access it at https://github.com/antoniolg/Kotlin-for-Android-Developers In order to insert a row data into CityForecastTable.NAME , I have to pass a vararg values by Source Code fun SQLiteDatabase.insert CityForecastTable.NAME vararg fun SQLiteDatabase.insert 1: The author make a extension toVarargArray() to convert a MutableMap<String, Any?> to Pair<String, Any?> , I don't know whether there is a better way to do that. Do I need to use a extension function? toVarargArray() MutableMap<String, Any?> Pair<String, Any?> 2: The author have to use the code it.value!! in Code C , I don't know if the code fun <K, V : Any> Map<K, V?>.toVarargArray(): Array<out Pair<K, V?>> = map({ Pair(it.key, it.value) }).toTypedArray() is right? it.value!! fun <K, V : Any...