I have two different interfaces
interface ColumnSet {
<V, I extends Column & Input<V>> V getValue(I column);
}
interface ParameterSet {
<V, I extends Parameter & Input<V>> V getValue(I value);
}
where the types Column
and Parameter
are simply marker interfaces to stop Column
s being used where Parameter
s should be and vice-versa. Behind the scenes I would therefore like to have a single class that implements them both as follows:
class ObjectSet implements ColumnSet, ParameterSet {
@Override public <V, I extends Input<V>> V getValue(I input) {
...
}
}
Logically it seems like ObjectSet.getValue
should be a valid override for both ColumnSet.getValue
and ParameterSet.getValue
as it takes any Input<V>
as an argument which is upper bounded by both Column & Input<V>
and Parameter & Input<V>
. However Java 9 doesn't recognise it as overriding either of them reporting The method getValue() of type ObjectSet must override or implement a generic supertype method
.
Is this a limitation of generics in Java or am I missing something fundamental?
(Obviously I can't create two separate methods in ObjectSet
due to them having the same erasure, which leaves me with the alternative of giving different names for the two getValue
methods in the interfaces which I'm trying to avoid).