Skip to content

Repository files navigation

Null Safety

void main(List<String> args) {
  var map = {'A': 1, 'B': 2, 'C': 3};
  map["D"] = map['A']! + (map['B'] ?? 0);
  print(map);
}

mapの値はnullである可能性があるのでmap['A']!と書くことでコンパイラにnullではないことを保証している。 他にもmap['A'] ?? 0と書くことでnullの場合??の右辺とすることでnullにならないことを保証する方法もある。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages