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.

Comments

Popular posts from this blog

Tuning ext4 for performance with emphasis on SSD usage

Java 8: Default Interface Implementations, The Diamond Problem, Multiple Inheritance, and Precedence

Tuning ext3 for performance without losing its data integrity potential