In my android app, I have a map of <String, Any?> and the value of the key could be an Int or String or null.
Currently, I do it like this:
map[key]?.let {
val value = it as Int
// use value here
}
If there a way to have a shortcut like Swift
if let value = map[key] as? Int {
}
So it's like a single line to check for nullity and cast it on the spot
you can use
(map[key] as? Int)?.let {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With