Skip to content

Instantly share code, notes, and snippets.

@kwalrath
Last active February 21, 2020 22:20
Show Gist options
  • Save kwalrath/edd31bcbee9299bdbdb7050567439f03 to your computer and use it in GitHub Desktop.
Save kwalrath/edd31bcbee9299bdbdb7050567439f03 to your computer and use it in GitHub Desktop.
nullsafety1-solution
// Copyright 2019 the Dart project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
// Try using `?`, `!`, and `late` to clean up the analysis
// errors in this code!
class MyClass {
late int val;
// Sometimes I get an error: Non-nullable instance field 'val'
// must be initialized - line 12
MyClass() {
val = 3;
}
}
void main() {
int? a = null;
int? b = a;
final myClass = MyClass();
a = 1;
b = 2;
print('$a, $b, ${myClass.val}');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment