我有这三个接口作为连贯接口API(其中很多方法链接的发生)的一部分:如何在Java中重用常用的扩展接口方法?
interface VerifierA extends VerifierC {
VerifierA method1();
// other methods elided
}
interface VerifierB extends VerifierC {
VerifierB method1();
// other methods elided
}
interface VerifierC {
VerifierA commonMethod();
}
通过声明commonMethod()
作为VerifierA
我可以再链方法 commonMethod().method1()
但不commonMethod().method2()
;
如何根据需要让commonMethod()
在VerifierC
返回VerifierA
或VerifierB?
我觉得这已经问http://stackoverflow.com/questions/1069528/method-chaining-inheritance-don-t-play-well-一起或http://stackoverflow.com/questions/9655335/method-chaining-how-to-use-getthis-trick-in-case-of-multi-level-inheritance – pringi
通读引用的答案,我是害怕我无法将其应用于仅由接口组成的环境... – Andrejs
为什么不简单地让commonMethod返回VerifierC并在VerifierB中覆盖以返回VerifierB和VerifierA以返回VerifierA? – david