Class 关于dart中类的常量构造函数
构造函数已设置为常量构造函数。为什么在创建实例时必须先指定常量标识符,然后才能将其指定为常量实例。我想知道这个设计的意图Class 关于dart中类的常量构造函数,class,dart,constructor,Class,Dart,Constructor,构造函数已设置为常量构造函数。为什么在创建实例时必须先指定常量标识符,然后才能将其指定为常量实例。我想知道这个设计的意图 void main(List<String> args) { const a1 = Foo(1); const b1 = Foo(1); //good!! assert(identical(a1, b1)); var a2 = Foo(1); var b2 = Foo(1); //NOT the same instance! ass
void main(List<String> args) {
const a1 = Foo(1);
const b1 = Foo(1);
//good!!
assert(identical(a1, b1));
var a2 = Foo(1);
var b2 = Foo(1);
//NOT the same instance!
assert(!identical(a2, b2));
}
class Foo<T> {
final T arg1;
//Is const here just for the sake of grammatical unity?
//↓↓↓
const Foo(this.arg1);
}
void main(列表参数){
常数a1=Foo(1);
常数b1=Foo(1);
//很好!!
断言(相同(a1,b1));
var a2=Foo(1);
var b2=Foo(1);
//不同的例子!
断言(!等同(a2,b2));
}
福班{
终末T-arg1;
//const在这里仅仅是为了语法统一吗?
//↓↓↓
const Foo(this.arg1);
}