最佳答案
真的不可能在 dart 中为一个类创建多个构造函数吗?
如果我有这个构造函数
Player(String name, int color) {
this._color = color;
this._name = name;
}
然后我尝试添加这个构造函数:
Player(Player another) {
this._color = another.getColor();
this._name = another.getName();
}
我得到以下错误:
缺省构造函数已定。
我不想通过创建一个包含大量非必需参数的构造函数来寻找变通方法。
有什么好办法解决这个问题吗?