如何摆脱这些as String
演员?
我想要做的是更改fun
定义,但我不知道该如何做...在{<}}中包含String
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
}
答案 0 :(得分:5)
删除通用定义并使用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
}