简体   繁体   English

在命名参数中=和:之间的Dart差异

[英]Dart difference between = and : in named parameters

class Student {
  String name;
  int age;
  int id;

  Student({this.name, this.id = 101, this.age: 20});
}

What is the difference between = and : in above constructor? 在上面的构造函数中, =:什么区别? Both seems to do the same job. 两人似乎做同样的工作。

From the documentation: 从文档:

Deprecation note: Old code might use a colon (:) instead of = to set default values of named parameters. 弃用注释:旧代码可能使用冒号(:)而不是=来设置命名参数的默认值。 The reason is that originally, only : was supported for named parameters. 原因是最初只有:支持命名参数。 That support is likely to be deprecated, so we recommend that you use = to specify default values. 该支持可能已被弃用,因此我们建议您使用=来指定默认值。

Source: https://dart.dev/guides/language/language-tour 资料来源: https//dart.dev/guides/language/language-tour

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM