0
我玩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']
哦!謝謝我需要更小心,或者我需要休息一下..)) – 2015-03-25 12:30:10