How does Kotlin handle nullability at the type system level, and what are the ?. safe call operator and the ?: Elvis operator for ?
Answer
Kotlin distinguishes at the type level itself a nullable type, like String?, from a non-nullable type, like String: the compiler forbids assigning null to a non-nullable type and forces explicit handling of the null case for a nullable type, which eliminates a large share of the NullPointerExceptions found in Java at compile time. The ?. operator performs a call only if the value isn't null, and returns null otherwise, without throwing an exception. The ?: Elvis operator supplies a fallback value if the expression on its left is null, letting you write concise null handling in a single line.
Common trap
The trap is believing Kotlin fully eliminates the NullPointerException risk: the !! operator forces a non-null access and still throws if the value is null after all, and interop with Java code lacking nullability annotations can introduce unexpected null values into a Kotlin type assumed to be non-nullable.