🎯
【Dart】型の確認方法
is
を使う
-
Male
とFemale
という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