class Student implements Comparable<Student>
{
private String name;
private int age;
Student(String name,int age)
{
this.name=name;
this.age=age;
}
public int hashCode()
{
return name.hashCode()+age*34;
}
public boolean equals(Object obj)
{
if(! (obj instanceof Student))
throw new ClassCastException("类型不对");
public int compareTo(Student s)
{
int num =new Integer(this.age).compareTo(new Integer(s.age));
if (num==0)
return this.name.compareTo(s.name);
return num;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class MapTest
{
public static void main(String[] args)
{
HashMap<Student,String> hm =new HashMap<Student,String>();