It sounds like you want to accomplish multiple inheritance, inheriting from both a View
and a Layout
. This is not possible in Java. You can accomplish something similar with composition. If your GenericView
must also provide the functionality given by AbstractLayout
, then you can accomplish it like this:
public interface Layout {
// Layout functions
public void doLayout();
}
public class GenericView<T extends AbstractLayout> implements Layout {
private final T delegateLayout;
// Construct with a Layout
public GenericView(T delegateLayout) {
this.delegateLayout = delegateLayout;
}
// Delegate Layout functions (Eclipse/IntelliJ can generate these for you):
public void doLayout() {
this.delegateLayout.doLayout();
}
// Other GenericView methods
}
public class VerticalLayout extends AbstractLayout {
public void doLayout() {
// ...
}
}
After this, you can actually do this:
new GenericView<VerticalLayout> (new VerticalLayout());
Hope this helps.
LAYOUTTYPE
it doesn't add anything to interface. – ChrissyAbstractLayout
. I do see many problems with it nevertheless - functions that are defined more than once for example and let's not ignore Type Erasure - but I can also see why someone may want to use something like this at times. – Lazaro