You are viewing a single comment's thread from:

RE: Building a Mine Sweeper Game using Dart's Flutter Framework (Part 4, Final)

in #utopian-io8 years ago (edited)

Final is a convention that comes from Java. Final variables can contain any value, but once assigned, a final variable can't be reassigned to any other value. So if I write final x = 10; and then try to write x = 11; then it will throw an error because I am trying to resign the variable x. final is also used for instance variables in an object, this means that if you use final for a property inside of an object and pass that property to the constructor then the property will not have an implicit setter method created for it.

class SomeClass {
  final int a, b;
  SomeClass(this.a, this.b);
}

void main() {
  var sc = SomeClass(10, 20);
  print(sc.aa); //prints out 10
  sc.a = 30; //Warning, no such setter method for a or b.
}

It is kind of important to keep in mind that the final keyword does not make the variable's object immutable.

class Person {
  String name;
  int age;
  Person(this.name, this.age);
}

void main() {
  final person = Person("John", 52);
  person.age = 32; //this is valid even though the person variable is final
  print(person.age); //prints out 32
}

If you want to play around with some dart to check to see how things work, you can use the dartpad website though I am pretty sure DartPad still uses Dart 1 syntax this means you would need to add new keywords to some of the pieces of code above.

Sort:  

alright thanks 😁
Any good resources to get started on DartLang?

The dart website is a very nice little place to start if you want to look at the language and its features. They've got some nice little tutorials as well.

You can also check out the Dart-awesome GitHub page (every programming language has its own "awesome" GitHub page, just google "language name" awesome).

Thanks again @tensor, if I have doubt I will comment in the post 😁

Its not a problem.

Good luck.

Coin Marketplace

STEEM 0.08
TRX 0.29
JST 0.035
BTC 106577.96
ETH 3697.21
USDT 1.00
SBD 0.58