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

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

    One of aspect than can consider in comparison dynamic vs var is taking into account behavior when using var declaration with initialization at the same time there is not possibility to change type which in case of dynamic is.

    But dynamic vs var is not the question what I would ask. I would ask more what is difference between dynamic vs Object.

    Here is a DO annotate with Object instead of dynamic to indicate any object is allowed.

    It is hard to feel it at the beginning, but dynamic I would relate to generic type argument.

提交回复
热议问题