【发布时间】:2019-10-12 05:08:44
【问题描述】:
class Student {
String name;
int age;
int id;
Student({this.name, this.id = 101, this.age: 20});
}
上述构造函数中的= 和: 有什么区别?两者似乎都做同样的工作。
【问题讨论】:
class Student {
String name;
int age;
int id;
Student({this.name, this.id = 101, this.age: 20});
}
上述构造函数中的= 和: 有什么区别?两者似乎都做同样的工作。
【问题讨论】:
来自文档:
弃用说明:旧代码可能使用冒号 (:) 而不是 = 来设置 命名参数的默认值。原因是,原来, only : 支持命名参数。这种支持很可能 已弃用,因此我们建议您使用 = 指定默认值 价值观。
【讨论】: