Is there a way to avoid the mess of adding all types to a class definition when implementing such an interface?
MyInterface.java
import java.util.List;
abstract class BaseA {}
abstract class BaseB {}
abstract class BaseC {}
interface MyInterface<T extends BaseA, U extends BaseB, V extends BaseC> {
public void foo( List<? extends T> list );
public void bar( List<? extends U> list );
public void baz( List<? extends V> list );
}
MyImplementation.java
class A extends BaseA{}
class B extends BaseB{}
class C extends BaseC{}
class MyImplementation implements MyInterface<A,B,C> {
public void foo( List<? extends A> list){}
public void bar( List<? extends B> list){}
public void baz( List<? extends C> list){}
}
What I don't like about this is that the material that I think is method specific, like the type of parameters, mixes up with the class declaration. As in this case, where for each general method in the interface I have to add one formal type to the "bracket section".
Is there any other way to achieve the above (forcing the calling party of the implementation to use a specific subclass of the parameter class in the interface) without any “mess”?
, question.