![](/img/trans.png)
[英]Is there any way to cast a Context to an Activity directly inside the constructor with Kotlin?
[英]Kotlin: Check if null and cast it directly
在我的Android应用程序中,我有一个<String, Any?>
的映射,键的值可以是Int或String或null。
目前,我这样做:
map[key]?.let {
val value = it as Int
// use value here
}
如果有办法拥有像Swift这样的快捷方式
if let value = map[key] as? Int {
}
所以它就像一条线来检查无效并将其投射到现场
您可以使用
(map[key] as? Int)?.let {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.