/null_safety.dart Secret
Created
February 25, 2022 10:10
Language Tour | Dart ... Null Safety
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// int aNumber = null; // コンパイルエラー | |
int? aNumber = null; // エラーにはならない | |
print(aNumber.toString()); // "null"と出力される | |
//print(aNumber!.toString()); // 例外発生 | |
//int anotherNumber = aNumber; // コンパイルエラー | |
int anotherNumber = aNumber!; // コンパイル時にはエラーにならない(実行時に例外) | |
print(aNumber.toString()); // どちらも出力自体は同じ | |
print(anotherNumber!.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment