Lets say I have 2 interfaces which define some kind of container format holding a specific type of data.
public interface Content {
}
public interface Holder1<T extends Content> {
}
public interface Holder2<T extends Content> {
}
Now I want some converter which defines objects that can transform an object of type Holder1
into an Holder2
.
This converter should keep information about the kind of objects stored within the original object:
public interface ConverterPrototype1 {
public <U extends Content> Holder2<U> convert(Holder1<U> source);
}
But I also want to be able to restrict the type of Holder1
that some converter can work on:
interface ConverterPrototype2<U extends Content, V extends Holder1<U>> {
public Holder2<U> convert(V source);
}
Is there a way to combine the semantics of these 2 interfaces into a single one? Something like
//INVALID CODE!
interface CombinedConvertor<V extends Holder1> {
public <U extends Content> Holder2<U> convert(V<U> source);
}
I'm not sure if my title is suited for this problem, but I couldn't find a better description... Similar problems posted here always seemed to talk about different things.
Edit: After stumbling upon this link, I came up with following code. It is still invalid, but closer to actual java code.
//INVALID CODE!
interface CombinedConvertor<X extends Source<?>> {
public <U extends Content, V extends X & Source<U>> Target<U> convert(V source);
}