on Not Null
Executes the given block only if the receiver object is not null.
This function provides a concise and readable way to perform an action on a nullable object, avoiding an explicit null check.
Example:
val name: String? = "John"
name.onNotNull {
println("Name is not null")
}Content copied to clipboard
Parameters
block
The block of code to execute if the object is not null.