LinkedList,在这段代码中,为什么用remove删不掉Name的对象呀
package com.oristand.program;
public class Name {
String fristName, lastName;
public Name() {
}
public Name(String string, String string2) {
fristName = string;
lastName = string2;
}
public String toString() {
return (fristName + " " + lastName);
}
public int hashCode() {
return 31*fristName.hashCode()+lastName.hashCode();
}
public boolean equals(Object obj) {
Name name = new Name();
if (obj instanceof Name) {
return (fristName.equals(name.fristName))
&& (lastName.equals(name.lastName));
}
return obj.equals(name);
}
}
////////////////////////////////////////////////////////////////////////
package com.oristand.program;
import java.util.*;
public class TestHashSet {
public static void main(String[] args) {
Collection<Object> c = new LinkedList<Object>();
c.add("hello");
c.add(100);
c.add(new Name("f1", "l1"));
c.add(new Integer(100));
System.out.println(c);
c.remove("hello");
c.remove(new Integer(100));
c.remove(new Name("f1", "l1"));//为什么这里会删不掉
System.out.println();
System.out.println(c);
}
}