由於我的知識集基本上有兩個方法equals()和hashcode(),根據它確定的值包含的值相等並避免重複輸入,但是在下面的程序中我得到困惑,即使包裝類也有兩種方法重寫,那麼爲什麼它接受重複值?爲什麼設置允許重複的字節整數和長整型值
代碼:
Collection col=new LinkedHashSet();
col.add(new Long(65));
col.add(new Byte((byte) 65));
col.add(new Integer(65));
col.add("A");
System.out.println(col);
答:65,65,65,A] 但我預期[65,A]
長L =新龍(65); \t \t System.out.println(l); \t \t Integer it = new Integer(65); \t \t System.out.println(it); \t \t System.out.println(l.equals(it)); – pranta
謝謝你了! – pranta