[英]Can you call a parent method that has been overridden in Haxe?
Haxe allows child constructor classes to call the parent's constructor using super()
, but tying to use super()
outside of the constructor method triggers an error. Haxe允许子构造函数类使用super()
来调用父构造函数,但在构造函数方法之外使用super()
会触发错误。 Is it possible for a child to call a parent's method if that method has been overridden? 如果该方法已被覆盖,则孩子可以调用父方法吗?
Hastily written example: 匆匆写的例子:
class Parent {
var thing:Bool;
public function someFunc(){
if(this.thing){
return "TRUE!";
} else {
return "FALSE!";
}
}
}
class Child extends Parent {
var thing2:Bool;
public override function someFunc() {
if(this.thing2){
return "TRUE!";
} else {
return someFunc(); //call to parent function?
}
}
}
Yes that is possible with the super
keyword. 是的,这可以通过super
关键字实现。
public override function someFunc() {
if (this.isWorking) {
return true;
} else {
return super.someFunc();
}
}
http://haxe.org/manual/types-class-inheritance.html http://haxe.org/manual/types-class-inheritance.html
super.someFunc() in the Child is what you want. 子级中的super.someFunc()是您想要的。
(super() always means the parent class' constructor, which can only be called from the child's constructor) (super()始终表示父类的构造函数,只能从子类的构造函数调用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.