The following code got error 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));
}
while the following didn't, and strangely identical(myconst1, myconst2)
return false
when TestConst
indeed only has 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));
}