Created
June 10, 2021 16:07
-
-
Save yjbanov/5734ae97063d08b29aaa4e8672420cfa to your computer and use it in GitHub Desktop.
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
class IPromiseIAmImmutable { | |
IPromiseIAmImmutable(this.field); | |
final int? field; | |
} | |
class OhYeahWatchThis implements IPromiseIAmImmutable { | |
int? _field; | |
@override | |
int? get field { | |
_field = _field == null ? 1 : null; | |
return _field; | |
} | |
} | |
void main() { | |
checkNotNull(IPromiseIAmImmutable(5)); | |
checkNotNull(IPromiseIAmImmutable(null)); | |
checkNotNull(OhYeahWatchThis()); | |
} | |
void checkNotNull(IPromiseIAmImmutable object) { | |
if (object.field != null) { | |
print('object.field is not null. See for youself: ${object.field}'); | |
} else { | |
print('object.field is null. See for youself: ${object.field}'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment