Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 为什么可以';是否在as表达式中使用t Object.runtimeType?_Dart - Fatal编程技术网

Dart 为什么可以';是否在as表达式中使用t Object.runtimeType?

Dart 为什么可以';是否在as表达式中使用t Object.runtimeType?,dart,Dart,根据的Dart文档,字段的类型为type。这让人困惑,因为我从编译器那里得到一个错误,抱怨这个字段不是类型 请参见此示例代码: final double first = 1.0; final int second = 2; final third = second as double; // works fine, unlike declaration below. assert(first.runtimeType == double); // true final fourt

根据的Dart文档,字段的类型为
type
。这让人困惑,因为我从编译器那里得到一个错误,抱怨这个字段不是类型

请参见此示例代码:

final double first = 1.0;
final int second = 2;

final third = second as double;       // works fine, unlike declaration below.
assert(first.runtimeType == double);  // true

final fourth = second as first.runtimeType;
最后一行抛出此编译时错误:

名称“first.runtimeType”不是类型,因此不能在“as”表达式中使用


示例代码显示了
first.runtimeType==double
,那么它不就是将
\uuu作为first.runtimeType
等同于
\uuuu作为double

我认为它实际上很简单,
runtimeType
仅在运行时可用,编译器无法对其进行静态分析。

主持人注意-请在评论部分。