Safe Calls and the Not-Null Assertion
Understand how Kotlin's safe calls and not-null assertion operators help manage nullable types in your code. Learn to use safe calls to gracefully handle null values and apply not-null assertions when exceptions are needed, boosting code safety and reliability.
We'll cover the following...
We'll cover the following...
Safe calls
The simplest way to call a method or a property on a nullable value is with a safe call, which is a question mark and a dot (?.) instead of just a regular dot (.).
Safe calls work as follows:
If a value is
null, it does nothing and returnsnull. ...