Is Dynamic type or not? Allows Dart to have two types at the same
time?
If type annotated but variable not initialized the variable has
unknown type?
If type annotated but variable not initialized the variable has
unknown type?
This expression: null is String is obviously false.
- bob
This expression: null is String is obviously false.Playing Devil's advocate here, why is this obviously false? null is a valid value for a variable whose type is String so it seems to me that in Dart, null is a String, right?
My understanding (which I'd love to be corrected if I'm wrong) is that type annotations define the set of types that are assignable to a variable (some bucket in memory). On the other hand, the "is" operator tests the value IN the bucket, not the bucket itself.
`String name;` means that the "name" bucket can hold a String OR null. That doesn't mean that null is a string.
This expression: null is String is obviously false.Playing Devil's advocate here, why is this obviously false? null is a valid value for a variable whose type is String so it seems to me that in Dart, null is a String, right?Well, because it really doesn't behave like String. Can you call any of String's method on null? You can't (with the exception of toString, but you can call toString on anything).
You can assign null to String-typed variable, but that's a problem on its own, as you are well aware of (the billion dollar mistake and only recent "invention" of non-nullable types).
The first quotation in http://en.wikipedia.org/wiki/Tony_Hoare#Quotations suggests that they were invented more or less simultaneously, I think?