I had the same problem, and found a working solution:
interface Adapter<E> {} interface Adaptulator<I> { void add(Container<?, ? extends I> container); } static final class Container<E, I extends Adapter<E>> { public final Class<E> extl; public final Class<I> intl; public Container(Class<E> extl, Class<I> intl) { this.extl = extl; this.intl = intl; } } Why it's working
###Why it's working ToTo understand that, we need to state our requirements:
- Keep two different generics synchronized on something. In your case, this is the E.
- One of the two generic needs to have some extra inheritance, here it's I.
Creating an extra class allow to meet these two requirements, by creating a tight context.
- An extra requirement (but probably the most important) was the need of a generic method (not bound too much to our class).
This is solved by the permissive parameter Container<?, ? extends I>.
Note
It's just a guess, but in this kind of usage, in general, you quickly need a ? super A or ? super I somewhere.