Skip to content

Commit

Permalink
simplify nullable declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Nov 27, 2024
1 parent 099365e commit 6ef971e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/Kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| **Variable Declaration** | `int age = 25;` | `val age: Int = 25` | `let age: number = 25` |
| **Immutable Variable** | `final int age = 25;` | `val age: Int = 25` | `const age: number = 25` |
| **Type inference** | `var age = 25;` (only for local variables) | `val age = 25` (anywhere, also for return types) | `let age = 25` (anywhere, also for return types) |
| **Nullable declaration** | N/A (nulls allowed everywhere) | `var name: String? = null` | `name?: string` |
| **Nullable declaration** | N/A (nulls allowed everywhere) | `name: String?` | `name?: string` (undefined) |
| **Nullable dereferencing** | `Optional.ofNullable(person).map(p -> p.name).orElse(null)` (even more difficult with nested nullability) | `person?.name` | `person?.name` |
| **Nullable fallback** | `if (person.name != null) person.name; else "";` | `person.name ?: ""` | `person.name ?? ''` |
| **Function Declaration** | `int add(int a, int b) { return a + b; }` (only inside of classes) | `fun add(a: Int, b: Int) = a + b` | `function add(a: number, b: number) { return a + b }` |
Expand Down

0 comments on commit 6ef971e

Please sign in to comment.