本文介绍了Dart中的Dynamic和Object之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它们似乎都可以在相同的情况下使用.在类型检查等方面有不同的表示形式或不同的细微之处吗?
They both seem like they can be used in identical cases. Is there a different representation or different subtleties in type checking, etc?
推荐答案
动态类型部分/ECMA-ST/ECMA-408.pdf"rel =" noreferrer> Dart编程语言规范,第三版指出:
The section Type dynamic from the Dart Programming Language Specification, 3rd Edition states :
这意味着通过在dynamic
类型变量上调用任何方法都不会收到警告.对于类型为Object
的变量,情况并非如此.例如:
That means you will not get warnings by calling any method on a dynamic
typed variable. That will not be the case with a variable typed as Object
. For instance:
dynamic a;
Object b;
main() {
a = "";
b = "";
printLengths();
}
printLengths() {
// no warning
print(a.length);
// warning:
// The getter 'length' is not defined for the class 'Object'
print(b.length);
}
在运行时,我认为您应该不会有任何区别.
At runtime, I think, you shouldn't see any difference.
这篇关于Dart中的Dynamic和Object之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!