Kotlin equivalent of Swift 'if let' for safe nullable type handling
Hi everyone! I've just started learning Kotlin after Swift and ran into a problem. In Swift, I often used the `if let` construct to safely unwrap optional values. For example:
```swift
var name: String? = "Alice"
if let unwrappedName = name {
print("Hello, \(unwrappedName)")
} else {
print("Name is nil")
}
```
This allows me to check if an optional has a value, and if so, automatically unwrap it and use it inside the block. Very convenient for avoiding force unwrapping.
In Kotlin, I see that types can be nullable (with `?`) and non-null. But I can't find a direct equivalent of `if let`. I tried writing:
```kotlin
var name: String? = "Alice"
if (name != null) {
println("Hello, $name")
}
```
But this only works if the variable