小序言.我是1.4 jdk的优秀java开发人员.在它之后,我已经切换到另一个平台,但在这里我遇到了问题所以问题强烈关于jdk 1.6(或更高:)).我有3个耦合类,与本机方法有关的耦合性质.贝娄是这三班的榜样
public interface A
{
public void method();
}
final class AOperations
{
static native method(. . .);
}
public class AImpl implements A
{
@Override
public void method(){
AOperations.method( . . . );
}
}
Run Code Online (Sandbox Code Playgroud)
所以有接口A,由AOperations以本机方式实现,而AImpl只是将方法调用委托给本机方法.这些关系是自动生成的.一切都好,但我有问题.有时像A这样的接口需要暴露迭代器功能.我可以影响接口,但不能改变实现(AImpl).
在C#中说我可以通过简单的部分来解决问题:(C#sample)
partial class AImpl{
... //here comes auto generated code
}
partial class AImpl{
... //here comes MY implementation of
... //Iterator
}
Run Code Online (Sandbox Code Playgroud)
所以,有部分或类似的java模拟.
编辑:根据@pgras的评论,我需要一些澄清.AImpl不在真空中,有一些工厂(本机实现)返回AImpl的实例,这就是为什么从AImpl创建继承不适用.
编辑2:可能它没有关系,但它是如何由JUnit 4完成的:
public class SomeTest {
...
//there is no direct inheritance from Assert, …Run Code Online (Sandbox Code Playgroud)