Specification <K, V> enter in `Pair <K, V>`

How can I get rid of these drives as String?

What I want to do is change the definition fun, but I'm not sure how to do it ... enable Stringthere

 parametersOf("appKey" to "asdas3334", "token" to "433432")

/**
 * Returns a new [Parameters] with the specified contents, given as a list of pairs
 * where the first component is the key and the second is the value.
 */
fun <K, V> parametersOf(vararg pairs: Pair<K, V>): Parameters {

    val p = Parameters(pairs.size)

    for ((key, value) in pairs)
        p.put(key as String, value as String)

    return p
}
+4
source share
1 answer

Just get rid of the general definition and use Pair<String, String>:

fun parametersOf(vararg pairs: Pair<String, String>): Parameters {

    val p = Parameters(pairs.size)

    for ((key, value) in pairs)
        p.put(key, value) 

    return p
}
+5
source

Source: https://habr.com/ru/post/1664345/


All Articles