简体   繁体   中英

Dart difference between = and : in named parameters

class Student {
  String name;
  int age;
  int id;

  Student({this.name, this.id = 101, this.age: 20});
}

What is the difference between = and : in above constructor? Both seems to do the same job.

From the documentation:

Deprecation note: Old code might use a colon (:) instead of = to set default values of named parameters. The reason is that originally, only : was supported for named parameters. That support is likely to be deprecated, so we recommend that you use = to specify default values.

Source: https://dart.dev/guides/language/language-tour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM