Const, Static and Final Keywords in Dart

static

“static” means a member is available on the class itself instead of on instances of the class. That’s all it means, and it isn’t used for anything else. static modifies *members*.

final

“final” means single-assignment: a final variable or field *must* have an initializer. Once assigned a value, a final variable’s value cannot be changed. final modifies *variables*.

const

“const” has a meaning that’s a bit more complex and subtle in Dart. const modifies *values*.

You can use it when creating collections, like const [1, 2, 3], and when constructing objects (instead of new) like const Point(2, 3). Here, const means that the object’s entire deep state can be determined entirely at compile-time and that the object will be frozen and completely immutable.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *