object instantiation syntax, ClassName() vs new ClassName()

Is there a difference between instantiating objects in these two ways?

void main() {
  var example = new ClassName()
}

vs

void main() {
  var example = ClassName()
}

Upvotes: 1

Views: 47

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657406

Since Dart 2.0 new is optional, so they are equivalent.
If the context requires const and new or const are omitted, then const is used automatically instead of new
(except for parameter default values because there the requirement for const might be dropped eventually)

Upvotes: 2

Related Questions