解决办法 复写hashcode方法
public class HashMapTest {
public static class CC {
private String cc;
public String getCc() {
return cc;
}
public void setCc(String cc) {
this.cc = cc;
}
public CC(String cc) {
this.cc = cc;
}
@Override
public boolean equals(Object arg0) {
CC testC = (CC) arg0;
return cc.equals(testC.getCc());
}
@Override
public int hashCode() {
return cc.hashCode();
}
}
public static void main(String[] args) {
Map
map.put(new CC("aa"), "bb");
System.out.println(map.get(new CC("aa")));
}
}
就可以正确获得结果
bb