Posts

Showing posts from April, 2012

Dart: Why "null is String" == false

Question: This expression:  null is String  is obviously  false . Bob Nystrom played Devil's advocate: 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? Gilad Bracha wrote : One could define things that way, but it serves very little purpose.  Typically, the goal of a test  o is T is to be allow one to use o as a T by invoking a method on it. If you make this answer true for null, you need to test for null separately, which is painful and error prone.  On the other hand, we do allow assignment, because of the general need for placeholder when a useful value is unknown.