镖。子 class 和构造函数初始化列表

Dart. Child class and constructor initializer list

我玩 Dart(翻阅 Dart 语言之旅),我发现我不能在子 类 上使用初始化列表。为什么?

main() {
  var rbt = new Robot.fromJson({'x':21, 'y':21});
}

class Human {

}

class Robot extends Human {
  int x;
  int y;
  Robot.fromJSON(Map map) : x = map['x'], y = map['y'] {
    print('Robot location is $x, $y');
  }
}

导致错误:

Exception: No constructor 'Robot.fromJson' declared in class 'Robot'.

NoSuchMethodError: method not found: 'Robot.fromJson'
Receiver: Type: class 'Robot'
Arguments: [Instance of '_LinkedHashMap']

Dart 区分大小写

fromJSON 对比 fromJson