Last active
February 21, 2020 22:20
-
-
Save kwalrath/edd31bcbee9299bdbdb7050567439f03 to your computer and use it in GitHub Desktop.
nullsafety1-solution
This file contains hidden or 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
// 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