public class ReflectTest2 {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
//Collection collections = (Collection)Class.forName(className).newInstance();
Collection collections = new HashSet();
ReflectPoint pt1 = new ReflectPoint(3,3);
ReflectPoint pt2 = new ReflectPoint(5,5);
ReflectPoint pt3 = new ReflectPoint(3,3);
collections.add(pt1);
collections.add(pt2);
collections.add(pt3);
collections.add(pt1);
collections.remove(pt1);
System.out.println(collections.size());
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception{
//Collection collections = (Collection)Class.forName(className).newInstance();
Collection collections = new HashSet();
ReflectPoint pt1 = new ReflectPoint(3,3);
ReflectPoint pt2 = new ReflectPoint(5,5);
ReflectPoint pt3 = new ReflectPoint(3,3);
collections.add(pt1);
collections.add(pt2);
collections.add(pt3);
collections.add(pt1);
//以下一行注释结果为1 不注释 结果为1 也就说明 你改了成员属性 而属性参与了计算hashcode 实体放到hashset数组中别的位置 删不了了、
//remove实际是失败的 多了 就为慢慢内存溢出
collections.remove(pt1);
System.out.println(collections.size());
}
}