【发布时间】:2022-01-14 11:55:46
【问题描述】:
我正在学习飞镖,飞镖的这种行为让我很烦
var a=10;
a="John"; //it generates an error, because a has integer data-type and we can't assign
//string or the value of any other data type because we have assigned an
//integer value
但同时,dart 允许我们编写
var a;
a=10;
a="John";
print (a) //it displays John
这意味着当变量在声明时初始化时,我们不能分配任何其他数据类型的值,但是如果变量在一行中声明并在第二行初始化,我们可以分配任何其他数据类型的值线。为什么飞镖会这样工作?
【问题讨论】:
标签: dart dart-null-safety