Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class 关于dart中类的常量构造函数_Class_Dart_Constructor - Fatal编程技术网

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);
}