简体   繁体   English

Dart null 与 Null

[英]Dart null vs Null

As far as a know, checking if a object is null or Null should be the same thing on Dart.据了解,检查 object 是null还是Null应该是 Z35900D987289A83AF101Z173 上的同一件事。

Something like:就像是:

print(bar == null);
print(bar is Null);

should print the same value.应该打印相同的值。 But, in a flutter app using firebase I got the following behaviour:但是,在使用 firebase 的 flutter 应用程序中,我得到了以下行为:

  print(snapshot.data['appearance']['details'].runtimeType); // Null
  print(snapshot.data['appearance']['details'].runtimeType == null); // false
  print(snapshot.data['appearance']['details'].runtimeType == Null); // true
  print(snapshot.data['appearance']['details'].runtimeType is Null); // false

the field value is null on firebase.字段值为null上的 null。 Why is it behaving like this?为什么会这样?

null is a value . null是一个 Null is a type . Null是一个类型

.runtimeType returns a Type . .runtimeType返回一个Type It cannot return a null value (that would mean the object has no type).它不能返回null值(这意味着 object 没有类型)。 null.runtimeType returns Null ; null.runtimeType返回Null that is, the null object has a type named Null .也就是说, null object 有一个名为Null的类型。

As for why .runtimeType is Null is false , see: What is the difference between 'is' and '==' in Dart?至于为什么.runtimeType is Null is false ,请看:Dart中的'is'和'=='有什么区别?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM