public class HashMapTest {
public static void main(String[] args) {
@SuppressWarnings("rawtypes")
HashMap map = new HashMap();
ObjTest t1 = new ObjTest(1);
map.put("1", "t1");
map.put("2", "t2"); //“2”的hashcode=50
map.put("3", "t3");
map.put("1", "t123444");
map.put(t1, "t1.object");
System.out.println(map.size());
System.out.println("2".hashCode());
System.out.println(t1.hashCode());
}
}
public class ObjTest {
private int k;
/**
*
*/
public ObjTest(int k) {
this.k = k;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
// TODO Auto-generated method stub
return 50;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return super.equals(obj);
}
}