Hacker News new | ask | show | jobs
by _hardwaregeek 2461 days ago
Non nullable reference types are so awesome! I'd love for the C# team to publish some posts on the creation of this feature. Most of the non nullable type systems exist in functional, or pseudo functional languages (Rust has rather functional semantics). It's very neat to see a honest to god mutable object oriented language implement non nullability. They probably had some interesting implementation challenges.

Also, is Java working on this too? I heard that they have Maybe, but that's pointless without non nullability.

4 comments

PHP has non-nullable reference types!

There are some really good write-ups by the C# team on the creation of non-nullable types and how it's implemented but my google-fu is failing me on it.

It's obviously a bit a of hack involving annotations/attributes but for the end user the result is pretty seamless.

Java does indeed have `java.util.Optional`. As a non-primitive type, it can itself be `null`, or be non-`null` but not contain a value.

In other words: I used to have `null` problems. Then I used `Optional`, and now I have two `null` problems!

Kotlin has them too.
Don't know about Java, but last I checked there were plans to add non-nullable reference types to Dart.