import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public int hashCode()
{
return name.hashCode()+age;
}
public boolean equals(Object obj)
{
if(!(obj instanceof Person))
throw new RuntimeException("类型不匹配");
Person p = (Person)obj;
return this.name.equals(p.name) && this.age == p.age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String toString()
{
return name+"::"+age;
}
}
class HashMapDemo
{
public static void main(String[] args)
{
Map<Person,String> map = new HashMap<Person,String>();
map.put(new Person("zhagnsan",20),"beijing");
map.put(new Person("zhangsan1",15),"nanjing");
map.put(new Person("zhangsan2",21),"wuhan");
map.put(new Person("zhangsan3",40),"tianjing");
Set<Map.Entry<Person,String>> entrySet = map.entrySet();
Iterator<Map.Entry<Person,String>> it = entrySet.iterator();
while(it.hasNext())
{
Map.Entry<Person,String> me = it.next();
Person key = me.getKey();
String value = me.getValue();
System.out.println(key+"::"+value);
}
}
}
以上代码去掉哪一个部分编译会报81个错误?
|
|