1

I'm just beginning to learn Dart and Flutter and I was wondering if there is any difference in the following declarations?

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

and

final _suggestions = <WordPair>[];

They both seem to exhibit the same behaviour but I'm wondering if there is some underlying difference?

I prefer the first declaration as I'm coming from a C/C++ back ground

1 Answer 1

3

There's no difference between them at all. The second syntax is here only to avoid pointless repetition.

Usually you should prefer the shorthand in Dart. According to the DO/DON'T of dart, there are some conditions in which you'll want to use the full syntax though.

 final List<Foo> globalVariable = <Foo>[];


 void func() {
   final localVariable = <Foo>[]
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer and the link :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.