为什么要调用超类覆盖方法?

时间:2013-09-21 11:30:30

标签: oop haxe nme

我在超类中覆盖了一个方法ini,但奇怪的是超级类中的ini方法仍被调用,虽然我没有使用super调用它

有什么想法吗?这是haxe 3中的一个问题吗? p.s:它是一个OpenFL项目,针对flash ..

class superClass{
 function ini():Void 
 {
   // this line should not be reached, but, it is reached .. !
 }
}

class subClass extends superClass{
 override function ini():Void 
 {
   // I Am not calling super ini here ..
 }
}

修改

以下是我的代码摘要,您可以在其中查看我的类集:

class EComponent extends Sprite
{

}

class Component extends EComponent
{

    public function new(aBoard:Board) 
    {
        ini();
    }
    function ini():Void 
    {
    // I am checking this manually, 
    // because ini is called even though its BeziereWire instance!
        if (Std.is(this, BeziereWire))
        return;
    }

    function iniRotators():Void 
    {

    }
}

class BeziereWire extends Component
{
    override function ini():Void 
    {
        iniRotators();      
    }
}

1 个答案:

答案 0 :(得分:3)

嗯,你的真实代码有问题。我做了一个测试项目,一切正常。 这是一个测试Main.hx - https://gist.github.com/sergey-miryanov/6658172

这是一个截图: And this is a screenshot

相关问题