【发布时间】:2019-05-28 14:02:27
【问题描述】:
有谁知道为什么下面的代码在 dart 中有效。 final 关键字用于定义常量变量。但下面的代码工作方式略有不同。如果我们使用具有不同值的const,它可以正常工作而不会出错。
void main() {
ExampleFinal exampleFinal = new ExampleFinal();
}
class ExampleFinal() {
final a = 5;
ExampleFinal() {
// The below statement will not create any error.
// But if you are remove const in below line it'll show a compile time error.
const a = 6;
print(a); // Prints 6
}
}
这是 dart 中的错误还是功能?文件中也没有提到。
【问题讨论】:
标签: dart