Dart has a concept of final. Most dynamic languages don’t have this concept.
What is final and what do I use it for?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
finalvariables can contain any value, but once assigned, a final variable can’t be reassigned to any other value.For example:
finalcan also be used for instance variables in an object. A final field of a class must be set before the constructor body is run. A final field will not have an implicit setter created for it, because you can’t set a new value on a final variable.It’s important to realize that
finalaffects the variable, but not the object pointed to by the variable. That is,finaldoesn’t make the variable’s object immutable.For example:
In the above example, the
addressvariable is marked as final, so it will always point to the object instantiated by thenew Address("anytown", "hi")constructor. However, the object itself has state that is mutable, so it’s perfectly valid to change the city. The only thing prevented byfinalis reassigning theaddressvariable.