Dart initialization and final, final late

37 views Asked by At

Hi developers!I'm using Dart for flutter. I'm trying to figure out why the code below doesn't need 'late' or 'final' for its variables. I know what these terms mean, but I'm puzzled about when and where the code is actually starting up, or "initializing".

Can someone break it down for me or give me some examples? I'd really appreciate it!

Thank you !

`

class Player {
   final String name;
   String mode; 
//`why we do not need late final or late here? `
   int xp;
   int level;
  
  Player(this.name, this.mode, this.xp, this.level); 

// as we declare variables with **'this'** , we initialized variable? 


  
  void playGame() {
    print("You choose $name, $mode. detail: xp = $xp, play level = $level",);
  }

}


void main() {
  var player = Player("King99", "Wizard",1000, 1); 
`// or initialization happened here?`
  player.playGame();
  var player2 = Player("Queen11", "Wizard", 5000, 3);
  player2.playGame();

}
0

There are 0 answers