Sdk: What is the purpose of const[]

Created on 20 May 2020  路  5Comments  路  Source: dart-lang/sdk

Hi,

Can anyone please tell me the purpose of the following statement

var list = const[1, 2, 3];
or
var list = const [];

Thanks and regards,
Amit Verma

area-meta type-question

All 5 comments

Please see https://dart.dev/guides/language/language-tour#final-and-const for an explanation of const.
The gist of it is
'Use const for variables that you want to be compile-time constants. If the const variable is at the class level, mark it static const. Where you declare the variable, set the value to a compile-time constant such as a number or string literal, a const variable, or the result of an arithmetic operation on constant numbers'

@a-siva you didn't get my Question and you closed the issue.. If you don't know the answer then please don't reply and close it.. i know what const, final and static are...
Now i know the Answer to my Question, i found out yesterday but i want you to reply bcoz you closed it...
WHAT IS THE _PURPOSE_ OF THIS STATEMENT ?
var list = const[1, 2, 3];

It is great that you found the answer to your question.
Please refrain from such comments that serve no purpose.

@a-siva Did I ask what are const variables ? NO.. my question was "what is the purpose of var list = const []; and you explained me about const variables and closed the issue.. that's what i didn't like.. So, please close the issue when the creator of the issue is satisfied..

In my understanding, var list = const[] just assigns an immutable List<dynamic> to variable named list, but you can reassign for later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmesserly picture jmesserly  路  3Comments

xster picture xster  路  3Comments

rinick picture rinick  路  3Comments

Hixie picture Hixie  路  3Comments

gspencergoog picture gspencergoog  路  3Comments