Created
December 8, 2022 00:49
-
-
Save navczydev/e8ba8324690b36b775ad78de305df8ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun processNullableName(name: String?) { | |
// Force unwrap !! | |
println("Name is: ${name!!}") | |
// Elvis operator ?: | |
println("Name is: ${name ?: "Kotlin"}") | |
// If statement | |
if (name != null) { | |
// Kotlin is smart enough to infer the type of name here as String ๐ | |
print("Name is: $name") | |
} | |
// Scope functions(let, also, etc.) | |
name?.let { nonNullableName -> | |
// Kotlin is smart enough to infer the type of name here as String ๐ | |
print("Name is: $nonNullableName") | |
} | |
// Chaining | |
val kotlin: Language? = Language("Kotlin") | |
print("Name is: ${kotlin?.name}") | |
} | |
data class Language(val name: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment