Open23

Dart と仲良くなる

kaito2kaito2

If you’re sure that a variable is set before it’s used, but Dart disagrees, you can fix the error by marking the variable as late:

なるほど。

kaito2kaito2
void main() {
  late int lineCount = f();

  print("=== Before eval ===");
  print(lineCount);
  print("=== After eval ===");
}

int f() {
  print('f() is evaluated !!!');
  return 777;
}

output

=== Before eval ===
f() is evaluated !!!
777
=== After eval ===
kaito2kaito2

A final variable can be set only once; a const variable is a compile-time constant.

認識相違なし

Note: Instance variables can be final but not const.

ふむふむ

kaito2kaito2

However, Dart programs can throw any non-null object—not just Exception and Error objects—as an exception.

どゆこと..?

kaito2kaito2

コンストラクタを定義しなくても引数なしのデフォルトコンストラクタが利用できる

kaito2kaito2

Initializer list あんまりわかってない

validation に使うっぽい

Point.withAssert(this.x, this.y) : assert(x >= 0) {
print('In Point.withAssert(): ($x, $y)');
}

kaito2kaito2

For example, a factory constructor might return an instance from a cache, or it might return an instance of a subtype. Another use case for factory constructors is initializing a final variable using logic that can’t be handled in the initializer list.

へー