1.普通构造函数:
class Person {
String name;
int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
}
简写:
class Person {
String name;
int age;
Person(this.name, this.age);
}
2.命名构造函数
class Person {
String name;
int age;
Person(this.name, this.age);
Person.sex() {
print('性别是...');
}
}

注:命名构造函数不可继承
本文介绍了Dart语言中的构造函数,包括普通构造函数的简写形式以及命名构造函数的使用,特别强调了命名构造函数不被子类继承的特点。
479

被折叠的 条评论
为什么被折叠?



