インターフェイスによって定義されたクラスがあります
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 フレームワークでカバーされていない依存関係を設定するため、メソッドは実装ごとに変化します。