| Start |
|---|
| Smart casts If the compiler can infer that an object can't be null at a certain point, you don't have to use the special operators anymore: Note: The compiler won't allow you to smart cast mutable variables that could potentially be modified between the null-check and the intended usage. If a variable is accessible from outside the scope of the current block (because they are members of a non-local object, for example), you need to create a new, local reference which you can then smart cast and use. |
| Assertion
|
| Nullable and Non-Nullable types Normal types, like |
| Eliminate nulls from an Iterable and array Sometimes we need to change type from |
| Null Coalescing / Elvis Operator Sometimes it is desirable to evaluate a nullable expression in an if-else fashion. The elvis operator, For instance: The expression above returns It is also possible to throw exceptions using the same syntax to abort code execution. Reminder: NullPointerExceptions can be thrown using the assertion operator (opens new window) (e.g. |
| Safe call operator To access functions and properties of nullable types, you have to use special operators. The first one, This will call To bring a nullable variable into scope as a non-nullable reference without making it the implicit receiver of function and property calls, you can use
|
| Null Coalescing / Elvis Operator Sometimes it is desirable to evaluate a nullable expression in an if-else fashion. The elvis operator, For instance: The expression above returns It is also possible to throw exceptions using the same syntax to abort code execution. Reminder: NullPointerExceptions can be thrown using the assertion operator (opens new window) (e.g. |
Read Article
https://develop.horje.com/learn/1434/reference