Abhineet Pandey
Abhineet Pandey

Reputation: 73

Mentioning Data type of list elements twice in Dart

I am new to Dart and Flutter, and I'm following a basic flutter tutorial, referred to from the official fultter docs.

At the 6th step in the tutorial, I came across this line of code:

final List<WordPair> _suggestions = <WordPair>[];

However, even if I changed the line to

final List<WordPair> _suggestions = [];

the code produced the same result. Note that this list stores some objects whose contents are displayed in the application.

Are both the cases same ? If yes, which one makes more sense semantically and should be preferred?

Upvotes: 0

Views: 174

Answers (1)

asterisk12
asterisk12

Reputation: 412

They both do the same thing - instantiate the list. If you don't add the <WordPair> beforehand, dart just assumes that the type is the same as the one on the left side. Either way is correct.

Upvotes: 1

Related Questions