Difference between “var” and “dynamic” type in Dart?

前端 未结 11 2058
攒了一身酷
攒了一身酷 2021-01-30 10:25

According to this article:

As you might know, dynamic (as it is now called) is the stand-in type when a static type annotation is not provide

11条回答
  •  醉梦人生
    2021-01-30 10:35

    try this in DartPad:

    void main() {
      dynamic x = 'hal';
      x = 123;
      print(x);
      var a = 'hal';
      a = 123;
      print(a);
    }
    

    you can change the type of x, but not a.

提交回复
热议问题