3 ms·
> NULL is a perfectly logical value to encounter or need. Great! Assign to it the type Null. This is legal: Null myNull = null; Make this illegal:
by mrkeen 6y ago
> NULL is a perfectly logical value to encounter or need.
Great! Assign to it the type Null.
This is legal:
Null myNull = null;
Make this illegal:
Integer i = null;
- munificent 6y agoThis is essentially what Dart does: https://api.dart.dev/stable/2.10.4/dart-core/Null-class.html https://api.dart.dev/stable/2.10.4/dart-core/Null-class.html The main change with adding nullable and non-nullable types to the language is that we no longer treat Null as a subtype of all types. Instead, you have to opt in using "?", which is basically syntactic sugar for "| Null".
- anfilt 6y agoNULL can be its own type, but the union between the set of integers and NULL is equally valid. However, that new set created by this union is not just integers. To represent a type that can be NULL or an integer it should be a different type. Like I said the problem again is mostly your data is not always contained to your language. If you export GPS coordinates some systems may treat this composite type incorrectly. So even if you have a strong type system people will just be lazy.