mardi 8 septembre 2020

Dart: When to use a getter vs a final field

I have a simple question to ask.

Consider the two code examples,

// 1
class A {
  final a = 23;
}

// 2
class A {
  get a => 23;
}

in [2], the final field is converted into a getter.

question: Under which circumstances should either type of codes be used? Which one is the dart's preferred way?

Aucun commentaire:

Enregistrer un commentaire