【发布时间】:2015-05-11 07:09:16
【问题描述】:
我尝试使用带有对象键的哈希图。 我可以填写哈希图。我可以使用 nbrCheminHashInter.keySet 显示 haskmap 的内容。但不可能得到,我总是收到一个空值。你能帮帮我吗?
public class MyKey<V> {
private V u;
private V v;
private V i;
// Constructor MyKey
public MyKey(V i,V u,V v){
this.i=i;
this.u=u;
this.v=v;
}
...
public String toString(){
return ""+this.i+""+this.u + ""+ this.v ;
}
}
for(V i:listeSommet){
for(V u:listeSommet){
for(V v:listeSommet){
nbrCheminHashInter.put(new MyKey<V>(i,u,v),0.0);}}}
//Print key and value
for(MyKey<V> key :nbrCheminHashInter.keySet() ){
System.out.println("Cle "+key+" value "+nbrCheminHashInter.get(key));
}
//print always null
for(V i:listeSommet){
for(V u:listeSommet){
for(V v:listeSommet){
System.out.println(nbrCheminHashInter.get(new MyKey<V>(i,u,v));
}
}
}
【问题讨论】:
-
覆盖 MyKey 类中的 hashCode