There is an analyzer/lint check to warn me when it is possible to use a const
constructor: https://dart-lang.github.io/linter/lints/prefer_const_constructors.html
(ie. using final a = const A();
instead of final a = A();
)
I think to understand the advantages (there will only ever be one instance with the same constant values for a const constructor). But why isn't this the default? Since dart 2 the new
can be omitted, so why didn't they change the definition of creating a new instance which can be created const
simply as const
instead of new
? I assume there must be some disadvantage to having everything const
?
(for example in a constant context like const [A()]
it is actually the same as const [const A()]
, so why not everywhere)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…