【发布时间】:2012-04-01 17:44:09
【问题描述】:
我有一个由接口定义的类
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.
}
}
如何调用另一个方法?
test.anotherMethod(); //Does not work.
我希望能够在实现中定义一些方法,只是因为在我的生产代码中,Test 接口涵盖了相当广泛的类并且由多个类实现。我使用实现中定义的方法来设置我的单元测试中 DI 框架未涵盖的依赖项,因此方法会随着实现而变化。
【问题讨论】:
标签: java interface methods upcasting