Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Created June 10, 2021 16:07
Show Gist options
  • Save yjbanov/5734ae97063d08b29aaa4e8672420cfa to your computer and use it in GitHub Desktop.
Save yjbanov/5734ae97063d08b29aaa4e8672420cfa to your computer and use it in GitHub Desktop.
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