群力方法调用 [英] Force base method call
本文介绍了群力方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有在部队继承类调用基实现Java或C#一个结构?你可以调用超()或碱(),但有可能有它抛出一个编译时错误,如果它不叫?这将是非常方便的。
Is there a construct in Java or C# that forces inheriting classes to call the base implementation? You can call super() or base() but is it possible to have it throw a compile-time error if it isn't called? That would be very convenient..
- 编辑 -
我主要是好奇覆盖方法。
I am mainly curious about overriding methods.
推荐答案
有不是,也不应该是什么做的。
There isn't and shouldn't be anything to do that.
我能想到的手最近的事情,如果像在基类中有这样的:
The closest thing I can think of off hand if something like having this in the base class:
public virtual void BeforeFoo(){}
public void Foo()
{
this.BeforeFoo();
//do some stuff
this.AfterFoo();
}
public virtual void AfterFoo(){}
和允许继承类覆盖BeforeFoo和/或AfterFoo
And allow the inheriting class override BeforeFoo and/or AfterFoo
这篇关于群力方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文