I would like to have a generic Interpolator class which can interpolate between instances of classes implementing the Interpolatable interface:
interface Interpolatable {
int getDimension();
Iterator <? extends Interpolatable> getIterator(double d);
}
class Coordinate extends AnotherClass implements Interpolatable {
public int getDimension() {return 3;}
public Iterator <Coordinate> getIterator (double d) {…}
}
class Interpolator <T extends Interpolatable> {
Interpolator () {
int dim = T.getDimension();
}
void doSomething (double d) {
Iterator <? extends Interpolatable> it = T.getIterator(d);
Interpolatable t = it.next();
…
}
}
Of course, the compiler complains about T.getDimension() and T.getIterator(d):
Cannot make a static reference to the non-static method getDimension()/getIterator(double) from the type Interpolatable.
However, the two methods cannot be made static, because they are defined in an interface. And at the time I would use them in Interpolator, I do not have an instance of Coordinate (or any Interpolatable) available.
Any suggestions?
(I understand why interface methods cannot be static; I just lack an idea how to elegantly solve a problem like this.)
statickeyword - can you check you have posted your code correctly?