我從JUNG庫中獲得了Hypergraph實現的接口和類。我擴展了Hypergraph接口來創建接口ISimpleHypergraph,以包含一些新方法,然後通過擴展類SetHypergraph和實現ISimpleHypergraph來創建一個新類SimpleHypergraph。如何在Java泛型中使用自定義類型
我還創建了具有id和權重字段的自定義SimpleV和SimpleH類型。現在我怎麼能在SimpleHypergraph中使用id字段實現幾個方法? SimpleHypergraph SimpleV和SimpleH內部不可識別。任何建議,甚至更好的方式來做到這一點?
請注意,接口Hypergraph和類SetHypergraph是JUNG libray的一部分。
public interface Hypergraph<V, H> {
// Other definitions
}
public interface ISimpleHypergraph<V, H> extends Hypergraph<V, H> {
H get(int id);
H get(Set<V> vSet);
// Other definitions
}
public class SetHypergraph<V, H> implements Hypergraph<V, H> {
protected Map<H, Set<V>> edges;
// Other fields
public SetHypergraph() {
edges = new HashMap<H, Set<V>>();
}
// Other methods
}
public class SimpleHypergraph<V, H> extends SetHypergraph<V, H> implements ISimpleHypergraph<V, H> {
public H get(int id) {
// How to use SimpleH.id and SimpleV.id here to get the
// searched Key entry from the Map<H, Set<V>> edges
}
public H get(Set<V> vSet) {
// How to use SimpleH.id and SimpleV.id here to get the
// searched Key entry from the Map<H, Set<V>> edges
}
}
public class SimpleV {
public int id;
public int weight;
public SimpleV(int id, int weight) {
this.id = id;
this.weight = weight;
}
// Other methods
}
public class SimpleH {
public int id;
public int weight;
public SimpleH(int id, int weight) {
this.id = id;
this.weight = weight;
}
// Other methods
}
研究通用邊界。另外,Java中沒有「實現」關鍵字。 – 2014-10-19 23:03:20
我正在尋找界限,但並沒有完全明白。你能否提供一些提示。 – joarderm 2014-10-19 23:36:25