[英]Specifiying <K,V> type in `Pair<K,V>`
How can I get rid of these as String
casts? 我怎样才能摆脱这些
as String
演员?
What I want to do is to change the fun
definition but I'm not sure how to do it... to include String
in there 我想要做的是改变
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
}
Just get rid of the generic definition and use a Pair<String, String>
: 只需删除泛型定义并使用
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.