Memory safe in D
Alex
akornilov.82 at mail.ru
Thu Mar 14 08:00:49 UTC 2024
On Thursday, 14 March 2024 at 00:32:47 UTC, cc wrote:
> On Wednesday, 13 March 2024 at 07:43:23 UTC, Alex wrote:
>> I mean nullable types like in Kotlin (originally in Ceylon)
>> and null safety model around it:
>> https://kotlinlang.org/docs/null-safety.html
>> ```d
>> if (a != null) {
>> a.run(); // ok, because type of variable 'a' is A (not
>> nullable) in this branch.
>> }
>> ```
>
> I like this, can the compiler handle cases like this?
> ```d
> if (a == null)
> return;
> a.run();
> ```
Yes, sure, Kotlin compiler handle it. The analyzer controls
variable type in each branch. After `if` type of `a` will be
non-nullable type `A`.
More information about the Digitalmars-d
mailing list