Since we have union types and explicit null now, it is easy to represent nullable type in Java as T | Null, but that is verbose compared to peers in Kotlin and Swift.
The union types and intersection types in Dotty is more powerful than competitors, but from users' point of view, typing T | Null is worse than T? in other languages.
Therefore, I propose to add a postfix type operator ?, just like | and & in union types and intersection types. In other words, T? = T | Null.
That would make sense if T | Null was very common in Scala. But is it? I have the impression null is rarely used, outside of Java interop. Put in other words: Why spend shorthand syntax on null, but not Option?
Since we have union types and explicit null now, it is easy to represent nullable type in Java as
T | Null
, but that is verbose compared to peers in Kotlin and Swift.The union types and intersection types in Dotty is more powerful than competitors, but from users' point of view, typing
T | Null
is worse thanT?
in other languages.Therefore, I propose to add a postfix type operator
?
, just like|
and&
in union types and intersection types. In other words,T? = T | Null
.