热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Dart,后面带有感叹号的标识符

最近我一直在用flutter开发移动应用程序,当我查看TickerProvider的源代码时,我看到以下几行:mixin

最近我一直在用 flutter 开发移动应用程序,当我查看TickerProvider的源代码时,我看到以下行:

mixin SingleTickerProviderStateMixin on State implements TickerProvider {
Ticker? _ticker;
@override
Ticker createTicker(TickerCallback onTick) {
...
_ticker = Ticker(onTick, debugLabel: kDebugMode ? 'created by $this' : null);
return _ticker!;
}
...
}

我对这条线很感兴趣:

return _ticker!;

我在前面看到了带有感叹号的布尔标识符,这意味着它将返回它的相反值,但我从未见过这个。有人能告诉我这是做什么的吗?

回答


这是 Dart 具有的零安全性的一部分。

你可以在这里阅读

If you’re sure that an expression with a nullable type isn’t null, you can add ! to make Dart treat it as non-nullable

例子:

int? aNullableInt = 2;
int value = aNullableInt!; // `aNullableInt!` is an int.
// This throws if aNullableInt is null.






推荐阅读
author-avatar
小王儿
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有