我在玩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']
飞镖区分大小写
fromJSON
与 fromJson
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句