Other concepts in Safe call operator
To perform a certain operation only for non-null values, you can use the safe call operator together with let
val listWithNulls: List<String?> = listOf("Kotlin", null)
for (item in listWithNulls) {
item?.let { println(it) } // prints Kotlin and ignores null
}
// If either `person` or `person.department` is null, the function is not called:
person?.department?.head = managersPool.getManager()
For more safe call operator details
Comments
Post a Comment