注释

代码中的注释帮助人们阅读代码,文档注释还用于生成API(应用编程接口)文档。Dart 支持三种注释:

单行注释和多行注释会被编译器忽略,而文档注释可用于Dart的文档生成工具,dart doc

单行注释

单行注释以//开头,从//到这一行的末尾,都会被Dart编译器忽略。

  // This line will be ignored by Dart compiler
  print('Hello');

多行注释

多行注释以 /* 开头,以*/ 结尾。

  /*
  This whole paragraph will be ignored by Dart compiler.
  Greetings to Dart.
  */
  print("Hello Dart!");

文档注释

文档注释以///开头(单行文档注释),或以/**开始以*/结束(多行文档注释)。在连续的行上使用 /// 与多行文档注释具有相同的效果。

// lib/ch0106_2.dart

/// A student class encapsulate student information,
/// including id, name and birthdate.
/// 
/// This class is immutable.
class Student {
  final int id;
  final String name;
  final DateTime birthdate;
  const Student(this.id, this.name, this.birthdate);
}

参考资料