I have the following two interfaces:
/**
* A marker interface to denote that an object implements a view on some other object.
*
* @param <T> The type of object that is viewed
*/
public interface View<T extends Viewable<View<T>>> {
}
/**
* An interface for objects that are viewable via a view.
*
* @param <T> The type of viewable object
*/
public interface Viewable<T extends View<?>> {
public void addViewCallback(final T view);
public void removeViewCallback(final T view);
}
I want to enforce the following:
- The type parameter of the
View
(called (a)), should be aViewable
that views upon that view (a). - The type parameter of
Viewable
(called (b)), should be aView
, which is viewable via that same viewable (b).
I think I got the bounds done for View
, but how am I going to make them work for Viewable
? What I got now compiles, but does not offer enough protection.
I cannot, as of now, formulate something that gets accepted which I do not want, I can however formulate what I do want, if that helps:
public class Hand implements Viewable<HandView>
public interface HandView extends View<Hand>
Deck implements Viewable<FieldView>
, whereDeck
andField
are not related, would be possible. – CoenosarcDeck implements Viewable<FieldView>
, is that your problem? – Fadeless