Dart笔记(11):symbol、enum、comments

符号 Symbol

Dart语言的标识符,在反射中用的很普及,特别是很多发布包都是混淆后的。

import 'dart:mirrors';

Symbol libraryName = new Symbol('dart.core');
MirrorSystem mirrorSystem = currentMirrorSystem();
LibraryMirror libMirror = mirrorSystem.findLibrary(libraryName);
libMirror.declarations.forEach((s, d) => print('$s - $d'));

枚举 Enum

适合用在常量定义,类型比较很方便。

enum Status { none, running, stopped, paused }
Status.values.forEach((it) => print('$it - index: ${it.index}'));

Status.none - index: 0
Status.running - index: 1
Status.stopped - index: 2
Status.paused - index: 3

注释 Comments

单行注释

// Symbol libraryName = new Symbol('dart.core');

多行注释

/*
 * Symbol
 * 
Symbol libraryName = new Symbol('dart.core');
MirrorSystem mirrorSystem = currentMirrorSystem();
LibraryMirror libMirror = mirrorSystem.findLibrary(libraryName);
libMirror.declarations.forEach((s, d) => print('$s - $d')); 
*/

文档注释

/// symbol
/// enum
/// comments
///
void main() {
  ...
}

你可能感兴趣的:(Dart笔记(11):symbol、enum、comments)