Junior — Middle
What happens when using the ? operator to access a property or method of an object?
sobes.tech AI
Answer from AI
The ?. operator in Android (Kotlin) is the safe call operator. It is used to access a property or method of an object that may be null.
If the object is not null, the property or method is called; otherwise, the expression returns null without throwing a NullPointerException.
Example:
val person: Person? = null
val name = person?.name // name will be null, not an error
Thus, ?. helps to work safely with nullable types.