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

前端 未结 11 2088
攒了一身酷
攒了一身酷 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:50

    A dynamic variable can change his type and a var type can't be changed.

    For example :

    var myVar = 'hello';
    dynamic myDynamicVar = 'hello';
    myVar = 123; // not possible
    myDynamicVar = 123; // possible
    

提交回复
热议问题