这是我的界面:
public interface Graph<V, E> {
Vertex<V> insert(V v);
Edge<E> insert(Vertex<V> from, Vertex<V> to, E e)
throws PositionException, InsertionException;
}
这是位置界面:
public interface Position<T> {
T get();
void put(T t);
}
这是我的类,它实现了Graph:
public class SparseGraph<V, E> implements Graph<V, E> {
private class Vertex<V> implements Position<V> {
V data;
public V get() {
return this.data;
}
public void put(V v) {
this.data = v;
}
}
private class Edge<E> implements Position<E> {
E identifier;
Vertex<V> from;
Vertex<V> to;
@Override
public E get() {
return this.identifier;
}
@Override
public void put(E e) {
this.identifier = e;
}
}
public Vertex<V> insert(V v) {
return null;
}
public Edge<E> insert(Vertex<V> from, Vertex<V> to, E e)
throws PositionException, InsertionException {
return null;
}
}
一切看起来都对我不错但是当我编译时,我得到了这个:
SparseGraph.java:36: error: insert(V#1) in SparseGraph cannot implement
insert(V#2) in Graph
public Vertex<V> insert(V v) {
^
return type SparseGraph<V#1,E>.Vertex<V#1> is not compatible with
Vertex<V#1>
where V#1,E,V#2 are type-variables:
V#1 extends Object declared in class SparseGraph
E extends Object declared in class SparseGraph
V#2 extends Object declared in interface Graph
我尝试过搜索这个问题,但由于缺少发布的代码,我发现的唯一类似问题没有答案。我的代码出了什么问题?感谢。