是否真的不可能为dart中的类创建多个构造函数?
在我的播放器类中,如果我有这个构造函数
Player(String name, int color) {
this._color = color;
this._name = name;
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试添加这个构造函数:
Player(Player another) {
this._color = another.getColor();
this._name = another.getName();
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
已定义默认构造函数.
我不是通过创建一个带有一堆非必需参数的构造函数来寻找解决方法.
有没有一个很好的方法来解决这个问题?