Skip to content

Instantly share code, notes, and snippets.

@woinary
Created February 25, 2022 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woinary/b30f3f1bc4149e7e040ee1c7c14caf44 to your computer and use it in GitHub Desktop.
Save woinary/b30f3f1bc4149e7e040ee1c7c14caf44 to your computer and use it in GitHub Desktop.
Language Tour | Dart ... Null Safety
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