LoginSignup
8
4

More than 5 years have passed since last update.

Dart static

Last updated at Posted at 2018-03-16

static

class宣言の中の変数メンバにstaticをつけると、クラス変数になり、そのクラスのインスタンスに関係なくただひとつそのオブジェクトが用意される。
new ~~でクラスのインスタンスを生成せずに使用可能

static
class Name {
  static final TARO = 'Taro';
  static final JIRO = 'Jiro';
  final saburo = 'Sanro';
}

main(){
  print(Name.taro);// Taro
  print(Name.saburo);//No static getter 'saburo' declared in class 'Name';
}
8
4
0

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
8
4