4 ms·
No, this is valid in languages with nullable types: String s = null; But this is not legal in languages without them: String s = None; In those languages, i
by sanderjd 6y ago
No, this is valid in languages with nullable types:
String s = null;
But this is not legal in languages without them:
String s = None;
In those languages, in order to have a value of None, it must be of type Option<String> (or whatever the syntax is), and in order to get a value of type String, you must assert its presence.
This is a fundamental difference with many ramifications. It really isn't just "the same but with better compile support".
- Larrikin 6y agoThat is legal in languages with poor null support. That statement would not be valid in Kotlin for example.
- _28jh 6y agoString s = null; That's not possible with nullable types. The whole point of nullable types is to mark types that can be null. So this is possible: String? s = null; But now it's not much different than this: Option<String> s = None; My point is that these are fundamentally the same thing. The only difference is syntax, ergonomics, and compiler support.
- munificent 6y agoString s = null; This is a compile error in Dart now. We added nullable types in order to make all other types not nullable. So unless you explicitly opt in to nullability by putting "?" on the type, you can a type that does not permit null.
- dragonwriter 6y ago> No, this is valid in languages with nullable types: > String s = null; Only in languages with default-nullable types, (where the non-nullable form, if it exists at all, would be something like “String s!”); in languages with explicity billable types, the above is not allowed, because you would need to explictly opt-in to nullability: String s? = null