Webstorm errors The class Task does not have a default constructor
on GreatTask
, I expect Task
being a default constructor of `Task.
I am looking forward to create a contract
of a Task
, such that upon Task.run()
, for each member of the list chain
Task.chain[i]
gets executed as it was a member of Task
, otherwise I expect an uncaught error
.
I am wondering what should I correct as first, the code or the configuration of Webstorm.
abstract class Task {
List chain;
Task(this.chain);
void run() {
this.chain.forEach((el) => this.el());
}
}
class GreatTask extends Task {
List chain;
GreatTask(this.chain);
String hi() {
return 'hi';
}
}
The "default constructor" is (technically) the one that is added if you don't add any constructors yourself. It'll be YourClass(): super();
.
The term "default constructor" is also commonly used about any no-name zero-argument generative constructor. That's what the error here is saying.
Because GreatTask(this.chain);
is the same as GreatTask(this.chain): super();
and the superclass Task
does not have a no-name zero-argument generative constructor for super()
to refer to, you have an error.
Günther's answer solves the problem by making the GreatTask
constructor call the existing Task(List list)
constructor instead of the non-existing Task()
constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With