LoginSignup
7
0

More than 3 years have passed since last update.

Dartのコンストラクタのあとのコロン

Last updated at Posted at 2020-04-17

initializer listと呼ばれるもので、

  1. assert
  2. fieldの初期化
  3. 他のコンストラクタ(super含む)
    がサポートされており、,でつなげて表現できる。
 import 'dart:math';
 class Point extends SomeParent {
  final num x;
  final num y;
  final num distanceFromOrigin;
  Point(x, y)
      : assert(x != null),
        assert(y != null),
        x = x,
        y = y,
        distanceFromOrigin = sqrt(x * x + y * y),
        super(x, y);
  }
7
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
0