
上QQ阅读APP看书,第一时间看更新
Type checking and casting
Dart has optional typing, as you already know, so type checking operators may be handy for checking types at runtime:
- is: For checking whether the operand has the tested type
- is!: For checking whether the operand does not have the tested type
The output of this code will be different depending on the context of the execution. In DartPad, the output is true for the check of the double type; this is due to the way JavaScript treats numbers, and, as you already know, Dart for the web is precompiled to JavaScript for execution on web browsers.
There's also the as keyword, which is used for typecasting from a supertype to a subtype, such as converting num into int.