The problem is that ZeroMapping extends both Vector<LinearMapping> and Vector<ConstMapping> .
To fix this, we will change the generic parameter V from LinearMapping and ConstMapping to the lower bounds of their individual classes so that they can extend the generic Vector<V> , which provides more flexibility. I hope this will record your intention to do LinearMapping both Mapping and Vector (for yourself only).
EDIT : in this case, you may need 3 general parameters: 2 for capturing the Mapping and 1 for attaching the Vector relationship to other LinearMappings of the same type.
Then ZeroMapping follows in the same format.
I included the @LuiggiMendoza suggestion in the answer below.
interface Vector<V extends Vector<V>> { int dimension(); V plus(V v); V times(double c); } interface Mapping<U extends Vector<U>, V extends Vector<V>> // Does not inherit from Vector because the set of all mappings is an // infinite-dimensional vector space. { V map(U u); }
An example of how the class will be implemented can be:
class RealVector implements Vector<RealVector> { // methods here .. // } class RealLinearMapping implements LinearMapping<RealVector, RealVector, RealLinearMapping> { @Override public RealVector map(RealVector u) { ... } @Override public RealLinearMapping plus(RealLinearMapping v) { ... } }
source share