Skip to content
Go back

dart

Published:  at  13:03

late

late String description;

void main() {
  description = 'Feijoada!';
  print(description);
}

用途,场景:

// This is the program's only call to readThermometer().
// 如果`temperature`从未使用该变量,则`readThermometer()`永远不会调用昂贵的函数
late String temperature = readThermometer(); // Lazily initialized.

final const

实例变量可以是 final 但不是 const

class P {
  // const c = 'c'; ❌
  final b = 1;
  static const String a = 'a';
}

不同:

var p1 = const Point(1, 2, p);
const p2 = Point(1, 2, p);

p1 p2 指向同一个对象

identical ==

== 操作符在比较对象时,会检查对象的 equals 方法(可以被重载),用于确定对象的 ” 相等性 ”。

而 identical 仅仅检查对象引用的 ” 同一性 “。它只关心对象的引用


Suggest Changes

Previous Post
conda
Next Post
flutter

Most Related Posts

  • ES6 基础

    Published:  at  12:40

    这篇博客主要介绍了ES6的基础特性,包括let/const声明、变量解构赋值等新语法的使用方法和注意事项

  • low code

    Published:  at  20:30

    low code

  • javascript scope

    Published:  at  13:14

    javascript scope

  • css

    Published:  at  20:39

    css

  • codec in js

    Published:  at  17:00

    codec in js