class Human{
Human(double height, int color) {
this._height = height;
this._color = color;
}
Human.fromHuman(Human another) {
this._height = another.getHeight();
this._color = another.getColor();
}
}
new Human.fromHuman(man);
Этот конструктор можно упростить от
Human(double height, int age) {
this._height = height;
this._age = age;
}
до
Human(this._height, this._age);
Именованные конструкторы также могут быть закрытыми, начав имя с _
Необходимы конструкторы со списком инициализаторов полей final
:
class Human{
final double height;
final int age;
Human(this.height, this.age);
Human.fromHuman(Human another) :
height= another.height,
age= another.age;
}