Whats ?? = Dart中的运算符 [英] Whats ??= operator in Dart

查看:65
本文介绍了Whats ?? = Dart中的运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Flutter源代码中看到的新赋值运算符:

This is the new assignment operator I see in Flutter source code:

splashFactory ??= InkSplash.splashFactory;
textSelectionColor ??= isDark ? accentColor : primarySwatch[200];

这个赋值运算符是什么意思?

what's the meaning of this assignment operator?

Flutter中的示例源代码

推荐答案

?? =是一个新的可识别null的运算符.具体地说,?? =是可识别空值的赋值运算符.

??= is a new null-aware operators. Specifically ??= is null-aware assignment operator.

??如果为null运算符. expr1 ??如果不是 null ,则expr2 的结果为 expr1 ,否则为 expr2 .

?? if null operator. expr1 ?? expr2 evaluates to expr1 if not null, otherwise expr2.

?? =空感知分配. v ?? = expr 导致分配 v 仅当 v null 时, expr .

?.空感知访问.如果 x 不是 null ,则 x?.p 的值为 xp ,否则为 null .

?. null-aware access. x?.p evaluates to x.p if x is not null, otherwise evaluates to null.

这篇关于Whats ?? = Dart中的运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆