Jim Belton
Jim Belton

Reputation: 231

Why do I get the following error from dart when I try to use inheritence?

When I run:

#import('package:logging/logging.dart');

class Trace extends Logger {
    Trace(String name) : super(name);
}

dart says:

'file:///home/jim/Code/dart/trace/Trace.dart': Error: line 6 pos 26: super class constructor 'Logger.' not found
    Trace(String name) : super(name);

I'm following the example in the technical overview:

class Square extends Rectangle {
  Square(num size) : super(size, size);
}

What am I doing wrong?

Upvotes: 2

Views: 442

Answers (2)

Kai Sellgren
Kai Sellgren

Reputation: 30212

The Logger class does not have any constructors. It has factories.

You tried to create a class that extends Logger and specified a default constructor that tried to call Logger's default constructor, which does not exist.

Maybe you were looking for something like this:

import 'package:logging/logging.dart';

class Trace extends Logger {
  factory Trace(String name) {
    return new Logger(name);
  }
}

main() {
  var i = new Trace('foo');

  i.on.record.add((LogRecord record) {
    print(record.message);
  });

  i.severe('blaa!');
}

Upvotes: 1

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76213

The error occurs because you try to extend a class (Logger) that has only a factory constructor. As suggested on the thread abstract classes and factory constructors you should consider implementing Logger instead of extending it.

Upvotes: 0

Related Questions