🎯

【Dart】型の確認方法

2021/03/22に公開

isを使う

  • MaleFemaleという2つのクラス
class Male {}
class Female {}
  • isを使うと型の判定ができる
void main() {
  final tarou = Male();
  final hanako = Female();
  
  print(tarou is Male);// true
  print(tarou is Female);// false
 
  print(hanako is Male);// false
  print(hanako is Female);// true
}

【参考】

Discussion