【发布时间】:2019-05-09 15:33:03
【问题描述】:
以下代码出现错误Error: Cannot invoke a non-'const' constructor where a const expression is expected.:
class TestConst {
final num x;
final num y;
TestConst(this.x, this.y);
}
void main() {
TestConst myconst1 = const TestConst(1,2);
TestConst myconst2 = const TestConst(1,2);
print(identical(myconst1, myconst2));
}
虽然以下没有,但奇怪的是identical(myconst1, myconst2) 返回false 当TestConst 确实只有const-constructor? :
class TestConst {
final num x;
final num y;
const TestConst(this.x, this.y);
}
void main() {
TestConst myconst1 = TestConst(1,2);
TestConst myconst2 = TestConst(1,2);
print(identical(myconst1, myconst2));
}
【问题讨论】:
标签: dart