Timur Fayzrakhmanov
Timur Fayzrakhmanov

Reputation: 19657

Dart. Child class and constructor initializer list

I play with Dart (leaf through Tour of the Dart Language) and I found that I can't use initializer list on child classes. Why?

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');
  }
}

Causes an error:

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

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

Upvotes: 0

Views: 468

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658263

Dart is case-sensitive

fromJSON vs fromJson

Upvotes: 3

Related Questions