简体   繁体   English

Dart const 构造函数 - 它可以是默认的吗?

[英]Dart const constructor - could it be default?

Why can't const be inferred, if we get warnings from Lint to use it?如果我们从 Lint 收到使用它的警告,为什么不能推断 const? Why, if possible, all classes constructors aren't by default const?如果可能的话,为什么所有类的构造函数都不是默认的 const? This would let our code much more clean.这将使我们的代码更加干净。

The main point of using const is not to assist the compiler in optimizations but to protect yourself from mistakes which means it prevents you from inadvertently modifying something you didn't expect to be modified.使用 const 的主要目的不是帮助编译器进行优化,而是保护自己免受错误的影响,这意味着它可以防止您无意中修改您不希望修改的内容。

Generally it makes it easier to program a when there is too many variables you dont.通常,当您没有的变量太多时,它会使编程更容易。 No need to memorize which one should be modified and which one shouldn't.无需记住哪个应该修改,哪个不应该修改。

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

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