我有一个由接口定义的类
public interface Test {
void testMethod();
}
Test test = new TestImpl();
public class TestImpl implements Test {
@Override
public void testMethod() {
//Nothing to do here
}
public void anotherMethod() {
//I am adding this method in the implementation only.
}
}
我该如何调用anotherMethod?
test.anotherMethod(); //Does not work.
我希望能够在实现中定义一些方法,因为在我的生产代码中,Test接口涵盖了相当广泛的类,并由多个类实现.我使用实现中定义的方法来设置单元测试中DI框架未涵盖的依赖关系,因此方法从实现变为实现.