In some Java code I have an interface like this:
interface A<T> {
T produce();
compare(T x, T y);
}
I have different implementations, such as:
class B extends A<int[]> {
int[] produce() {...}
compare(int[] x, int[] y) {...}
}
The issue is how to capture the implementation specific generic type. The following doesn't work:
A<T> a = new B();
T x = a.produce();
T y = a.produce();
a.compare(x, y);
Because of course the type T
does not refer to what's inside B
. (In fact it doesn't refer to anything.)
Is there a way to make T
capture the generic type of B
?