我有几个课程
public interface Identity<I> {
public I getId();
}
public interface Position<T,I> {
public I getId();
public T getData();
public int getX();
public int getY();
}
public interface SpartialIndex<T,I extends Position<T,I>> {
public void add(T t);
public void addAll(SpartialIndex<T,I> index);
//
public void remove(T t);
public void removeAll(SpartialIndex<T,I> index);
//
public int size();
//
public SpartialIndex<T,I> getRectangle(int left,int top,int right,int bottom);
public SpartialIndex<T,I> getCircle(int centerX,int centerY,int radius);
//
public void translate(SpartialIndex<T,I> index,int translateX,int translateY);
public List<T> getClosests(int x,int y);
public List<T> get(I id);
}
但是当我尝试创建默认实现时,我似乎无法使泛型工作。我不会用这条消息编译。
绑定不匹配:类型I不是有界的有效替代 参数&lt; I extends Position&lt; T,I&gt;&gt; SpartialIndex类型&lt; T,I&gt;
public class DefaultSpartialIndex<T,I> implements SpartialIndex<T,I> {
public DefaultSpartialIndex() {
super();
}
@Override
public void add(T t) { }
@Override
public void addAll(SpartialIndex<T,I> index) { }
@Override
public void remove(T t) {}
@Override
public void removeAll(SpartialIndex<T, I> index) { }
@Override
public int size() {
return 0;
}
@Override
public SpartialIndex<T, I> getRectangle(int left, int top, int right,int bottom) {
return null;
}
@Override
public SpartialIndex<T, I> getCircle(int centerX, int centerY, int radius) {
return null;
}
@Override
public void translate(SpartialIndex<T, I> index, int translateX,int translateY) { }
@Override
public List<T> getClosests(int x, int y) {
return null;
}
@Override
public List<T> get(I id) {
return null;
}
}
答案 0 :(得分:3)
只是一个错字。
替换:
public interface SpartialIndex<T,I extends Position<T,I>>
由:
public interface SpartialIndex<T,I> extends Position<T,I>