Following on from my last question here:
I have a class like so:
public class nVector<T extends nVector<?>> {
int i;
public T add(T a) {
}
}
And want the following to occur:
public T add(T a) {
T b = this.clone();
b.i += a.i;
return b;
}
However the instantiation of the Generic type T
is not allowed. Yet I can easily include an instance of T in my arguments.
I'm doing this because I have multiple children of the T
type that inherit all methods from nVector
and act upon themselves in an 'enclosed environment'. (i.e. They only take their own type as an argument, not other children)
Any way to fix this? The issue is, is that I have to return something of type T
, and not nVector<?>
.