我在dart代码实验室中研究了可迭代对象,偶然发现了以下代码片段:
class EmailAddress {
String address;
EmailAddress(this.address);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(a) other is EmailAddress &&
(b) runtimeType == other.runtimeType &&
address == other.address;
....
(a)行和(b)行有什么区别?对我来说,他们似乎也一样。或更普遍地问:使用is-operator和使用对象的runtimeType属性检查dart中的运行时类型有什么区别?
aSet is Iterable
- 这是 true
aSet.runtimeType == Iterable
这是 false
因此,is检查处理子类。
另外,我们确实建议您避免使用runtimeType
。特别是在编译为JavaScript时。它确实可以炸毁您编译的应用程序大小。
我将在该代码实验室上发布一个问题!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句