Skip to content

Commit

Permalink
feat: Update Null safety docs (#4389)
Browse files Browse the repository at this point in the history
* Update Null safety docs

This PR contains updates to the Null safety docs such as content improvement and runnable code snippets.

* Added explicit information about null safety with var and val

* Added validate="false" to NPE examples

* fix: replace anchor

* Anastasiia review

* chore: rephrased a couple of sentences

* Daniel review

* chore: fix an anchor

* chore: rewording a sentence.
  • Loading branch information
AlejandraPedroza authored Sep 13, 2024
1 parent be4fb90 commit 1ef645d
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 98 deletions.
2 changes: 1 addition & 1 deletion docs/topics/competitive-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fun main() {
```

Note the use of Kotlin's
[null-assertion operator](null-safety.md#the-operator) `!!`
[null-assertion operator](null-safety.md#not-null-assertion-operator) `!!`
after the [readLine()](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/read-line.html) function call.
Kotlin's `readLine()` function is defined to return a
[nullable type](null-safety.md#nullable-types-and-non-nullable-types)
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/jvm/java-to-kotlin-nullability-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ After the check is passed successfully, the compiler treats the variable as if i
in the scope where the compiler performs the check.

If you don't perform this check, the code will fail to compile with the following message:
"Only [safe (?.)](null-safety.md#safe-calls) or [non-nullable asserted (!!.) calls](null-safety.md#the-operator) are allowed
"Only [safe (?.)](null-safety.md#safe-call-operator) or [non-nullable asserted (!!.) calls](null-safety.md#not-null-assertion-operator) are allowed
on a [nullable receiver](extensions.md#nullable-receiver) of type String?".

You can write the same shorter – use the [safe-call operator ?. (If-not-null shorthand)](idioms.md#if-not-null-shorthand),
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/keyword-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ Kotlin supports the following operators and special symbols:
* `===`, `!==` - [referential equality operators](equality.md#referential-equality).
* `<`, `>`, `<=`, `>=` - [comparison operators](operator-overloading.md#comparison-operators) (translated to calls of `compareTo()` for non-primitive types).
* `[`, `]` - [indexed access operator](operator-overloading.md#indexed-access-operator) (translated to calls of `get` and `set`).
* `!!` [asserts that an expression is non-nullable](null-safety.md#the-operator).
* `?.` performs a [safe call](null-safety.md#safe-calls) (calls a method or accesses a property if the receiver is non-nullable).
* `!!` [asserts that an expression is non-nullable](null-safety.md#not-null-assertion-operator).
* `?.` performs a [safe call](null-safety.md#safe-call-operator) (calls a method or accesses a property if the receiver is non-nullable).
* `?:` takes the right-hand value if the left-hand value is null (the [elvis operator](null-safety.md#elvis-operator)).
* `::` creates a [member reference](reflection.md#function-references) or a [class reference](reflection.md#class-references).
* `..`, `..<` create [ranges](ranges.md).
Expand Down
Loading

0 comments on commit 1ef645d

Please sign in to comment.