1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Dart] staticとは

Posted at

staticの使い方

static はクラスのプロパティ・メソッドはクラスをインスタンス化せずに使用できるようにするもの。

具体例
void main() {
  print(Car().wheelNum); //Car()でインスタンスを作成している。
  print(Bike.wheelNum); //Bikeなのでインスタンスを作成していない。
}

class Car {
  int wheelNum = 4;
}

class Bike {
  static int wheelNum = 2;  
}

まとめ

インスタンスを作成しない方が、メモリ的にも良いことが多そう。
constと合わせてうまく使うようにしていきたい。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?