如何在Dart中调用超级构造函数? [英] How do I call a super constructor in Dart?
本文介绍了如何在Dart中调用超级构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Dart中调用超级构造函数?是否可以调用命名的超级构造函数?
How do I call a super constructor in Dart? Is it possible to call named super constructors?
推荐答案
是的,语法接近C# ,这是一个默认构造函数和命名构造函数的示例:
Yes it is, the syntax is close to C#, here is an example with both default constructor and named constructor:
class Foo {
Foo(int a, int b) {
//Code of constructor
}
Foo.named(int c, int d) {
//Code of named constructor
}
}
class Bar extends Foo {
Bar(int a, int b) : super(a,b);
}
class Baz extends Foo {
Baz(int c, int d) : super.named(c,d);
}
这篇关于如何在Dart中调用超级构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文